Mona Coder
Mona Coder

Reputation: 6316

Exporting Bootstrap DOM - HTML to PDF by DOMPDF

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?

Upvotes: 3

Views: 11850

Answers (2)

Y. E.
Y. E.

Reputation: 804

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.

Upvotes: 0

Charlie Moreno Solis
Charlie Moreno Solis

Reputation: 31

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();

Upvotes: 2

Related Questions