Search code examples
phphtmlcsspdfdompdf

How to set full width to a specific HTML element in DOMPDF


I'm using DOMPDF to generate a pdf file in php program, here is may code to generate the pdf :

  public static function generatePDF()
    {
        $pdf = App::make('dompdf.wrapper');
        //$pdf->setPaper('A4','landscape');
        $pdf->loadView('pdfview');
        return $pdf->download('Report.pdf');
    }

in my pdfview, I have a HTML element with properti like this :

<div style="background-color: #353535; max-width:100%; margin:0; padding:0" >
...
...
...
</div>

As we can see, the width is full and there is also not margin or padding, but the pdf result is a little bit different like this : enter image description here

So How do I make this div element fills the entire pdf width ? Thank you so much


Solution

  • Try this :

        <style>
          @page {
            size: a4 landscape; 
            margin:0.9;padding:0.9; // you can set margin and padding 0 
          } 
          body {
            font-family: Times New Roman;
            font-size: 33px;
            text-align: center;
            border: thin solid black;  
          }
        </style>