8

I'm using bootstrap grid to display and i want that my client download it in pdf so for that i'm using dompdf but dompdf is not able to apply bootstrap style. I cannot go back and turn my bootstrap grid to basic html tables and using different plugin to convert to pdf i found them difficult and time consuming(especially in installing composer and then updating i'm new ) is there any way out so that i can easily apply bootstrap style to my pdf

   $pr_dt=$_POST['hid'];//div elements which i want ot convert them to pdf and also contain bootstap lib link
   include_once("../assets/converter/dompdf/dompdf_config.inc.php");
   $dompdf =  new DOMPDF();
   $dompdf->load_html($pr_dt);
   $dompdf->render();
   $dompdf->stream("MRA.pdf");

or at least is there any online converter for bootstrap grid to html tables

3
  • dompdf's CSS support is still a little lacking for something as complex as Bootstrap. You can get a basic design working, but more complicated designs are not likely to produce the desired results. If you provide a sample of the HTML we can try to tweak the CSS to get better results.
    – BrianS
    Commented May 1, 2015 at 21:18
  • What you probably want is a headless browser, like PhantomJS. It does require installation on the server, but since it's based on webkit it produces results as good as any modern web browser.
    – BrianS
    Commented May 1, 2015 at 21:20
  • sorry but i don't access to my webserver for installation i can only upload my files when its done
    – MayuriS
    Commented May 2, 2015 at 5:48

8 Answers 8

4

Put All CSS codes in same page . Do not refer CSS to external link .

Work with inline tags like margin ,padding ,top and etc.

1
  • Yeah....This is basically the solution that helps your users download pdf faster
    – jovialcore
    Commented Jan 29, 2022 at 7:47
3

You need to make sure dompdf can find your CSS files. You can do this with set_base_path, for example:

$dompdf->set_base_path("/www/public/css/");

You also need a to specify the CSS file, something like:

<html>
  <head>
    <link type="text/css" href="style.css" rel="stylesheet" />
  </head>
<body>
...
3
  • now i'm getting Cannot find Font class fontmetrics_cls.php on lin 346
    – MayuriS
    Commented May 1, 2015 at 11:52
  • Make sure your dompdf is setup correctly. Check your setup.php and it should tell you what's wrong, for example: pxd.me/dompdf/www/setup.php
    – alan0xd7
    Commented May 1, 2015 at 12:15
  • DOMPDF_PDF_BACKEND is CPDF should i change this
    – MayuriS
    Commented May 1, 2015 at 12:26
3

I faced the same challenge and solved it by: Add the bootstrap.min.css code at the tag at the top of the page. N.B bootstrap 3 works best.

enter image description here

1

Include before the html code:

        $html = '<link rel="stylesheet" href="/css/bootstrap.min.css" />';
1

You can use the Bootstrap v3.3.6, it is working with DomPDF,
I have tested

0

'in response to the now i'm getting Cannot find Font class fontmetrics_cls.php on line 346'

This happens as you need to add Dompdf to your applications config to include modules. In zf2 its application.config.php in the modules section I hope that helps as I went hours looking for that without any documentation.

0
$content .= '<style>
'.file_get_contents("./bootstrap.min.css").'
</style>';

Add this into your html code.. it will print the raw css into the html code

0

check this. if you ned bootstrap in multi projects ,create a file php with this.

<?php
     echo '
       <style>
               todo el codigo de bootstrap
       </style>
    ';
?>

and in your code add a include 'bootstrap.php';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.