3

Using Bootstrap 3 and DOMPDF, I am trying to export some html nodes like:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="alert alert-success">
       <a href="#" class="alert-link">Test 1</a>
    </div>
    <div class="alert alert-info">
       <a href="#" class="alert-link">Test 2</a>
    </div>
    <div class="alert alert-warning">
       <a href="#" class="alert-link">Test 3</a>
    </div>
    <div class="alert alert-danger">
       <a href="#" class="alert-link">Test 4</a>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

but it is not taking the Bootstrap styles over to the PDF, is it possible to generate PDF from Bootstrap style? As far as I can tell from my research, the DOMPDF export HTML content to PDF but why not taking care about the Bootstrap Style?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mona Coder
  • 6,212
  • 18
  • 66
  • 128
  • dompdf doesn't yet support some CSS features relied on by bootstrap (e.g. `box-sizing`), and others are still works in progress (such as float). The problem could be how you are loading the HTML into dompdf and how it affects the path used to find the CSS. Can you update your code with the relevant PHP? – BrianS Mar 24 '14 at 14:00

2 Answers2

2

Have you ever tried this? https://stackoverflow.com/a/17186282/2811998

   $dompdf = new DOMPDF();
   $dompdf->set_base_path(realpath(APPLICATION_PATH . '/path/to/css/'));
   $dompdf->load_html($html);
   $dompdf->render();
Community
  • 1
  • 1
0

My response is late, but I'm still leaving it for a reference.

DOMPDF devs still working on Bootstrap support, and current support didn't work well for me either. So, I've looked for another solutions.

Based on what I've found and tested mPDF and wkhtmltopdf can handle Bootstrap layout.

mPDF doesn't require server root access for the library installation (wkhtmltopdf does), so it can be used as a replacement for DOMPDF when using Bootstrap, even though wkhtmlpdf provides better presentation results.

Y. E.
  • 687
  • 1
  • 10
  • 29