DomPDF content going off right side of PDF

42 Views Asked by At

I'm trying to use DOMPDF to make a PDF out of this: https://devcoursetransfer.northcarolina.edu/bdp.html

It is coming up up with this: https://devcoursetransfer.northcarolina.edu/Test.pdf

It's changing the aspect ratio of the image, but more importantly, it's running off the right side of the page. Is there any way I can fix these two problems?

Code below:

    // Instantiate and use the dompdf class
    $options = new Options();
    // can fetch remote files
    $options->set('isRemoteEnabled', true);
    $dompdf = new Dompdf($options);

    $dompdf->loadHtmlFile('https://devcoursetransfer.northcarolina.edu/bdp.html');

    $dompdf->setPaper('A4', 'portrait');

    $dompdf->render();

    ob_clean();
    $dompdf->stream('Test.pdf');
    exit;
      
1

There are 1 best solutions below

0
developer981 On

Figured it out through trial and error. There is a lot of CSS that DOMPDF doesn't handle correctly.

There is an element that has these styles:

#bdp-guide{
    width: 8.5in;
    padding: .5in;
    margin: 0px auto;
}

Which makes it look good on the web, but causes DOMPDF to shift everything to the right and off the PDF.

So, I added a class pdfview when creating a pdf, and added this CSS

#bdp-guide.pdfview {
    margin:auto; 
    padding: 0; 
    width: auto;
}

I plan to switch to a better tool soon.