user2809321 user2809321 - 3 months ago 35
PHP Question

DOMPDF, able to create pdf doc but the pdf itself failed to load

Hi I'm trying to use php to covert html to pdf. The code is able to run and I able to run it and download a pdf file but when I open the pdf file it gives me this error

enter image description here

This is the code I have to run the php


$html =
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.

$dompdf = new DOMPDF();


I have a feeling that I'm loading the html wrong so the contents of the pdf is actually messing up, any ideas?

^^^---- these spaces will corrupt the PDF

If you really do have those 3 spaces before your PHP opening tag, they will become part of the PDF file and corrupt it. Load up your "bad" pdf, do a file->save, and opening the file in a text/hex editor (NOT a pdf reader) and see what you're getting. Any PHP errors/warnings or other output before the actual PDF data will cause the PDF readers to see it as corrupted.