DOM pdf error

error when using dom pdf to generate pdf files from php records:
Error:
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
doctorbillTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
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:
https://www.experts-exchange.com/articles/32160/How-to-Fix-Just-About-Every-Common-PHP-Error.html

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.
doctorbillTechAuthor Commented:
Attached files:

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

pdf_workformPDF.php
This file uses the dom pdf files and has the following file as an include:
searchWorkFormPDF.php

Can you see where the issues may be?
pdf_workformPDF.php
searchWorkformCompany.php
searchWorkFormPDF.php
Chris StanyonWebDevCommented:
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/dompdf_config.inc.php 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">
    <head>
        <title>Chris Stanyon</title>
    </head>
    <body>
        <h1>Test PDF</h1>
    </body>
</html>

Open in new window

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

<?php
require_once("/includes/pdf/dompdf_config.inc.php");

ob_start();
include('template.php');
$html = ob_get_contents();
ob_end_clean();

$dompdf = new DOMPDF();
$dompdf->load_html($html);

$dompdf->render();
$dompdf->stream("test.pdf");

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doctorbillTechAuthor Commented:
Once again - thanks all
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PDF

From novice to tech pro — start learning today.