1

Hi all,

I'm looking for a solution to write two PDF's at one...

Let's say i make a PDF letter with an image as background, this file i use to display and mail.
Now when i want to print the letter (without the background image) i need a different PDF file.

So i've tried to do a second output with the same settings and content (except for the background img), but this returns an error.

Any suggestions?

2

here's part of my code:

// PDF with background image
ob_start();
?>
<page backtop="<?php echo $bodyT.'mm'; ?>" backbottom="<?php echo $bodyB.'mm'; ?>" backleft="<?php echo $bodyL.'mm'; ?>" backright="<?php echo $bodyR.'mm'; ?>" backimg="<?php echo $imgURL; ?>" backimgx="<?php echo $imgXpos; ?>" backimgy="<?php echo $imgYpos; ?>" backimgw="<?php echo $imgW; ?>" style="font-size: <?php echo $fontsize."pt"; ?>; <?php if ($font) { echo "font-family: ".$font.";"; } ?>" >

<?php
$content = ob_get_clean();
ob_end_clean();

// PDF without background image
ob_start();
?>
<page backtop="<?php echo $bodyT.'mm'; ?>" backbottom="<?php echo $bodyB.'mm'; ?>" backleft="<?php echo $bodyL.'mm'; ?>" backright="<?php echo $bodyR.'mm'; ?>" style="font-size: <?php echo $fontsize."pt"; ?>; <?php if ($font) { echo "font-family: ".$font.";"; } ?>" >

<?php
$content_print = ob_get_clean();
ob_end_clean();
?>

<?php
ob_start();

// here starts the rest of the content used for both files

//---------------------------------------------------------------------------------------------------------------

// then below we add the content to the previously saved content
$content .= ob_get_clean(); // add the content for the first document
$content_print .= ob_get_clean(); // add the content for the second document
ob_end_clean();




try {
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->pdf->SetAuthor($_SESSION['user']);
$html2pdf->pdf->SetTitle($TITEL);
$html2pdf->pdf->SetSubject('Factuur');
$html2pdf->pdf->SetKeywords($DOCUMENTNR, $TITEL);
$html2pdf->pdf->SetDisplayMode('fullpage'); */
$html2pdf->writeHTML($content);

// save the first document to the given filelocation
$html2pdf->Output($filelocation.$file_name, 'F');

$html2pdf->writeHTML($content_print);

// save the second document to the given (different) filelocation
$html2pdf->Output($filelocation_print.$file_name, 'F');

}

catch(HTML2PDF_exception $e) {
echo $e;
}
?>

this code returns an error on the second output: err05 HTML code invalid, all tags must be closed

3

okay... i've found the bug!

Here's what was basicly wrong...

$content .= ob_get_clean(); // add the content for the first document
ob_get_clean() > Get current buffer contents and delete current output buffer, so it's not available for the next part > $content_print
So, after replacing this with ob_get_contents(), it runs smoothly.

$content_print .= ob_get_clean(); // add the content for the second document and now delete the output buffer
ob_end_clean();

Secondly, i've found out that i need to use the complete script (as used for the first file) again for the second one, so the last part should be this:

try {
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->pdf->SetAuthor($_SESSION['user']);
$html2pdf->pdf->SetTitle($TITEL);
$html2pdf->pdf->SetSubject('Factuur');
$html2pdf->pdf->SetKeywords($DOCUMENTNR, $TITEL);
$html2pdf->pdf->SetDisplayMode('fullpage'); */
$html2pdf->writeHTML($content);

// save the first document to the given filelocation
$html2pdf->Output($filelocation.$file_name, 'F');

$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->pdf->SetAuthor($_SESSION['user']);
$html2pdf->pdf->SetTitle($TITEL);
$html2pdf->pdf->SetSubject('Factuur');
$html2pdf->pdf->SetKeywords($DOCUMENTNR, $TITEL);
$html2pdf->pdf->SetDisplayMode('fullpage'); */
$html2pdf->writeHTML($content_print);

// save the second document to the given (different) filelocation
$html2pdf->Output($filelocation_print.$file_name, 'F');

}

Basicly the first mistake caused the err05 because there is an unclosed <page tage since that is closed in the content used for both files!
The second one is just a matter of knowing that the created $html2pdf array is being cleared after creating a PDF.

Thanks for reading anyway! wink