Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply bootstrap style in dompdf

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

like image 232
MayuriS Avatar asked May 01 '15 11:05

MayuriS


3 Answers

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>
...
like image 104
alan0xd7 Avatar answered Oct 13 '22 05:10

alan0xd7


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

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

like image 28
Hesam Moosapour Avatar answered Oct 13 '22 05:10

Hesam Moosapour


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

like image 41
GeorgeKN Avatar answered Oct 13 '22 04:10

GeorgeKN