dompdf image overflow problem


I've got an issue with PDF generation currently my system is using dompdf to convert HTML to PDF this all works fine. However if the user inserts an image that is bigger than an A4 page the PDF screws up badly and all the content below the large image gets bunched up or isn't shown at all.

Here are two PDFs to show an example of the issue

This one is fine

This one you can see with the first image being bigger than the A4 page all the content following gets screwed up when it should be the same as the previous one.

What I'd ideally like to do is break the image into parts and span it across as many pages as required. Like what is accomplished in this LaTeX solution. Is there any possibility of doing this with dompdf? or any other PHP library for doing HTML to PDF?

I've looked into it myself and obviously I could chop up an image if its bigger than the A4 page. But problem is with that approach that need to know if there is text on the page before hand or anything like that so its not quite that simple.

Thank you all in advance. Any insight would be very much appreciated.

It would me much more helpful if you posted you html and css... Got two things in mind:

Option #1

Try to wrap your images in the additional DIV and explicitly set the width and overflow rules.

Option #2

Before I was a big fan of dompdf but after discovering wkhtmltopdf never looked back. wkhtmltopdf is a phenomenal tool that gets job done right. To try this solution do the following:

  1. Download static binary from project home page, it's architecture specific so pick the right one... you can download both; at runtime detect architecture and load appropriate binary
  2. Place the file in some directory accessible by your project, e.g.
  3. Run your script and generat html document; save it to some tmp file
    file_put_contents('/tmp/myfile.html', $html);
  4. Run the conversion command
    shell_exec('/path/to/my/proj/bin/wkhtmltopdf /tmp/myfile.html /tmp/myfile.pdf')
  5. Get contents of generated pdf, change response headers and server the file:
    header('Content-Type: application/pdf');

    echo file_get_contents('/tmp/myfile.pdf');