phpbootstrap-4bootstrap-5dompdf

how to use bootstrap in a PDF with dompdf?


I'm trying to generate a report filled with info from my DB, and I can show it correctly with HTML and boostrap, but when I try to render my html file, the bootstrap stops working.

<?php 
//this is my html:
ob_start(); 
?>

<!-- All my file goes here, including the <link></link> to the boostrap -->


<?php $html = ob_get_clean() ?>

Then, in another file (which i use to create the PDF) i did this:

<?php


require_once 'route/to/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();

include "firstFileWithHtml.php";
$options = $dompdf->getOptions();
$options->set(array('isRemoteEnabled' => true));
$dompdf->setOptions($options);

$dompdf->loadHtml($html);
$dompdf->setPaper("letter");

$dompdf->render();

$dompdf->stream("file_pdf", array("Attachment" =>false));


?>

And It generates the PDF preview, just without the boostrap.

is there an option i'm missing?

I tried downloading bootstrap, I tried with another versions (4.3.1, 5.0.2, 5.3.0), I tried using the CDN, but nothing is working.

I also tried the solutions in this answer, but putting the css in the same file didn't work, and the method set_base_path is deprecated.


Solution

  • I found the solution, Thanks to @ceejayoz for the hint.

    if I put the href like this:

    <link rel="stylesheet" href=""../user/bootstrap-5.0.2-dist/css/bootstrap.min.css">
    

    It didn't work. But if I use this instead:

    <link rel="stylesheet" href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/PROJECT/user/bootstrap-5.0.2-dist/css/bootstrap.min.css">
    

    it works like a charm.