YUNOOS PARVEZ ANSARI
YUNOOS PARVEZ ANSARI

Reputation: 13

mpdf after break page next page header text should be change

hello please check pdf sample, I'm using mpdf to generate a pdf document in php.

I got this pdf generated by the code below.

1st copy is perfect, but second copy of 1st page top header title show wrong i want to 2nd copy on header $title2

Can you help me?

<?php
include('mPDF/mpdf.php');
$mpdf = new mPDF('c', 'A4', '9', '', '10', '18', '55', '50', '50', '12', 'P');
$html = '

    <html>
    <head>
    </head>
    <body>';

for ($i = 1; $i < 80; $i++) {
    $html .= '<div>Here is the text of the first chapter</div>';
}
$html .= '</body>
    </html>';

$title1 = "<p style='text-align:right; margin:0px; font-size:15px;'>ORIGINAL </p>";
$title2 = "<p style='text-align:right; margin:0px; font-size:15px;'>DUPLICATE</p>";
$title3 = "<p style='text-align:right; margin:0px; font-size:15px;'>TRIPLICATE</p>";


$mpdf->SetHeader($title1 . $header);
$mpdf->SetFooter($footer . 'Page No. {PAGENO} of {nbpg}');
$mpdf->WriteHTML($html);
$mpdf->SetFooter($footer . 'Page No. {PAGENO} of {nbpg}');

$mpdf->WriteHTML('<pagebreak resetpagenum="1" pagenumstyle="1" suppress="" />');

$mpdf->SetHeader($title2 . $header);
$mpdf->SetFooter($footer . 'Page No. {PAGENO} of {nbpg}');
$mpdf->WriteHTML($html);
$mpdf->SetFooter($footer . 'Page No. {PAGENO} of {nbpg}');
$mpdf->Output();

PDF Sample

Upvotes: 0

Views: 4726

Answers (1)

Jason Aller
Jason Aller

Reputation: 3652

According to the documentation the SetHeader function can take three parameters, the third of which is $write.

This third parameter forces the Header to be written immediately to the current page. Use it if the header is being set after the new page has been added.

Change to:

$mpdf->SetHeader($title2 . $header, [], true);

and it should allow the second header to be seen.

You may also want to look at AddPage().

Upvotes: 2

Related Questions