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
https://dl.dropbox.com/u/65878041/OK.pdf
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.
https://dl.dropbox.com/u/65878041/Issue.pdf
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:
/path/to/my/proj/bin/wkhtmltopdf
file_put_contents('/tmp/myfile.html', $html);
shell_exec('/path/to/my/proj/bin/wkhtmltopdf /tmp/myfile.html /tmp/myfile.pdf')
Get contents of generated pdf, change response headers and server the file:header('Content-Type: application/pdf');
echo file_get_contents('/tmp/myfile.pdf');
I don't know how the images are being shown, but you can tell dompdf to split pages after or before a certain element. For example:
<div style='page-break-after:always;'>
<img src="PATH_TO_IMAGE" />
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With