DOMPDF Tips – HTML to PDF using PHP5

1. Always ask to save the file , don’t load the PDF directly. I have printing problems when printing it directly without saving.

2. Add memory limit to php.ini

ini_set("memory_limit","128M");

3. Debug the output html first before converting to pdf.

4. Load images on the same server and with relative paths. You can’t load images using “http://domain.com”.

5. Use wordwrap with caution.

6. Always add width to your table and first row cells

7. Make sure images are in correct format with correct extension. A BMP file with .jpg extension will trigger an error.

8. Avoid special characters if possible.

If you some trouble with DOMPDF, just comment and maybe I can help you out.

All are based on experience!

3 Responses to “DOMPDF Tips – HTML to PDF using PHP5”

  1. Gary says:

    Hi,
    Do you have any idea how to get background images show up proportionately to their actual widths? The issue i am having is,
    eg. if a table is 600px in width, and the bacground image is 800+px, the background image is still smaller than the table. The table widths are way out of proportion with image widths… It is crucial to my project that image dimensions actually be what they are. they are shrinking.

    Any help much appreciated.

    Gary

  2. admin says:

    Did you try to see it in HTML format first? if you can show me at least a preview then I can help.

    Also, try setting a width to your tables and cells. See if it works. If not, let me know.

  3. Gary says:

    Yeah, works great with HTML…have specified widths on table(mentioned.. 600px) thing is, i think it has something to do with the dpi… it was initially set to 150, i played around with it and got larger images at lower dpi… set to 95 now.. now i think i have to set values in my table in mm/cm or inches rather than pixels.. if i had a something that would calculate pixes into dpi, that would be great.. have not found a suitable one i could use yet… trial and error is the only way to go for me i guess

Leave a Reply