Monday, September 3, 2012

File does not begin with '%pdf-'

I am using mPDF to output code written in PHP to pdf.

I was trying to take 3 php pages and print them all to 1 PDF.

The first thing I did was add the following:

$mpdf->debug = true;

This then allowed the error to be shown.  It was "Output has already been sent from the script - PDF file generation aborted."

I ended up figure it out that I was missing ob_end_clean().

Here is the final code:

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

ShareThis