Ahmed
Ahmed

Reputation: 1533

TCPDF page count of html content

I am using TCPDF to generate a PDF document from dynamic html content which is stored as $html string. I then use the following code to make the PDF:

$pdf->writeHTML($html, true, false, true, false, '');

if I add the following line before outputting the file

    $totalPageCount = $pdf->getNumPages();

It can give me the total page count in that PDF document. However, before then outputting it using the code below:

    $pdf->Output('info.pdf', 'I');

Is there a way I can add some more html content if my page number meets the following condition:

if (($totalPageCount>=1) && ($totalPageCount % 2 != 0)) {

Upvotes: 0

Views: 2882

Answers (1)

Ahmed
Ahmed

Reputation: 1533

No replies, but it seems that the instance of $pdf lets you add more content using writeHTML. so what i've done is this:

$pdf->writeHTML($html, true, false, true, false, '');
$totalPageCount = $pdf->getNumPages();
if (($totalPageCount>=1) && ($totalPageCount % 2 != 0)) {
    $pdf->writeHTML('<div><tcpdf method="AddPage" /></div>This page is intentionally blank.', true, false, true, false, '');
}
$pdf->Output('info.pdf', 'I');

Upvotes: 1

Related Questions