DOM pdf error

doctorbill used Ask the Experts™
error when using dom pdf to generate pdf files from php records:
Unable to stream pdf: headers already sent

I have tried all the typical suggested solutions for this but I still get the error
I haven't posted any code yet because I am unsure of exactly what to post
I initially post this error in case anyone has a suggestion of whet the error is actually telling me / doing in terms of code
I am pretty sure it used to work on my server but I have not visited my code for some time so I just cannot remember if anything has changed
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

This is because you have code that is trying to set HTTP headers, but the HTTP headers have been sent already.

This is the same error as the PHP one:
Warning: Cannot modify header information - headers already sent

...which I cover in my article:

Basically, ANY output at all, even a line break or a single space, will tell PHP / the web server that you're done with the headers portion of the response and you're moving onto the body of the response. So more often than not, this is just a line break somewhere in an included / required file.


Attached files:

This file is the source file and the links "Create Individual PDF" sends "id2" data to the following page:

This file uses the dom pdf files and has the following file as an include:

Can you see where the issues may be?
Most Valuable Expert 2018
Distinguished Expert 2018
Hey Doctorbill,

gr8gonzo has already pointed out that this error is caused by data being sent to the browser before calling stream(). This can include any whitespace, so you need to track that down. In the files you've posted, pdf_workformPDF.php seems to have a blank line right at the top - remove that.

Check what's in the /includes/pdf/ file to make sure there's no data being output from there.

Also, you seem to be using an older version of DOMPDF, so you might want to consider updating to a later version.

To debug this problem, I would start by stepping back to a very basic setup. Create a very simple static HTML file just containing a Heading. Call it template.php

<!DOCTYPE html>
<html lang="en">
        <title>Chris Stanyon</title>
        <h1>Test PDF</h1>

Open in new window

And now create a php file containing the folliwing (call it test.php)


$html = ob_get_contents();

$dompdf = new DOMPDF();


Open in new window

Now call that test.php file in your browser and see if you get the test.pdf file. If you do, build up from there.


Once again - thanks all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial