mpdf after break page next page header text should be change - php

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

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().

Related

TCPDF: wrong page count

I'm creating a PDF with a custom header and footer but, I don't understand why, when I add an image in the footer, the total page count gets busted and added twice:
$logoFileName = 'images/image.png';
$logoX = 0; // 0mm
$logoY = $this->GetY()-10; // 0mm
$logoWidth = 200; // 15mm
$logo = 'Pagina ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages() . $this->Image($logoFileName, $logoX, $logoY, $logoWidth);
// $this->SetX($this->w - $this->documentRightMargin - $logoWidth);
$this->Cell(0,10, $logo, 0, false, 'R', 0, '', 0, false, 'T', 'M');
Results:
first page
second page
With same script, if I delete this->image() the count is correct.
I also add that, if I remove the following function from the script:
$this->getAliasNbPages()
so it becomes so:
$logo = 'Pagina ' . $this->getAliasNumPage() . '/' . $this->Image($logoFileName, $logoX, $logoY, $logoWidth);
the first page is correct masculine but the following ones are correct:
first page
second page

Set Custom Page Title for HTML2PDF created pdf

I am using HTML2PDF library of PHP to create PDF from HTML. My page url is as below ::
http://domain.com/admin/invoice/invoicedownload
To create pdf using below code ::
ob_start();
$width_in_mm = 240;
$height_in_mm = 250;
$html2pdf = new HTML2PDF('P', array($width_in_mm,$height_in_mm), en, true, 'UTF-8', array(15, 10, 15, 10));
$html2pdf->setDefaultFont('Arial');
$html2pdf->pdf->SetTitle('Invoice Details');
$html2pdf->writeHTML($pdf_template);
$html2pdf->Output($file_name,'I');
die();
This code open pdf view in browser new tab.
Issue I am facing is that that new tab title is set as "Invoice Details - invoicedownload" but I want it as "Invoice Details". Always url's last part is append in title.
Please help me for this.
Thank you in advance.
In order to define your own tab title, you can use the 'embed' html tag.
File n°1 (main):
html, body, embed
{
width: 100%;
height: 100%;
}
body
{
margin: 0;
padding: 0;
}
<!DOCTYPE html>
<html>
<head>
<title>Your title</title>
</head>
<body>
<embed src=/path-to-your-pdf type='application/pdf'/>
</body>
</html>
File n°2 (/path-to-your-pdf):
<?php
$html2pdf = new Html2Pdf('P, 'A4', 'en');
$html2pdf->writeHTML($pdf_template);
$html2pdf->output();
Hope this helps ;)

How to align left and right on same line in mpdf

I try this HTML code
<p class="alignleft">Text on the left.</p>
<p class="alignright">Text on the right.</p>
and CSS code
.alignleft{
float: left;
}
.alignright{
float: right;
}
include mpdf
ob_start();
..HTML..
$pdf = new mPDF('th', 'A4', '0', 'THSaraban','30','20','15');
$stylesheet = file_get_contents('mpdf/style_mpdf.css');
$html = ob_get_contents();
ob_end_clean();
$pdf->SetAutoFont();
$pdf->SetDisplayMode('fullpage');
$pdf->WriteHTML($stylesheet, 1);
$pdf->WriteHTML($html, 2);
$pdf->Output();
It worked on HTML but in mpdf doesn't
Thank you.
Try this:
$html= "<p align='left'>Text on the left.</p><p align='right'>Text on the right.</p>";
$mpdf->SetColumns(2, 'J');
$mpdf->WriteHTML($html, 2);
$pdf->Output();
Reference: here.

Dynamic Footer MPDF

I'm using mdpf and php to generate a PDF. I need to create a different footer every time I use the tag pagebreak.
My code is something like this (and it's not working this way)
$mpdf = new mPDF('c', 'A4');
$mpdf->SetHTMLFooter('First Article','O');
$html = 'Lots of text';
.
.
.
$html .= "pagebreak"; (this is a html tag)
$html .= 'More lots of text';
$mpdf->SetHTMLFooter('Second Article','O');
$mpdf->WriteHTML($html);
print $mpdf->Output();
How could I do that?
You need to flush the content with WriteHTML, then set a new footer.
$mpdf = new mPDF('c', 'A4');
$mpdf->SetHTMLFooter('First Article','O');
$html = 'Lots of text';
.
.
.
$html .= "pagebreak"; (this is a html tag)
$mpdf->WriteHTML($html); //flush
$html .= 'More lots of text';
$mpdf->SetHTMLFooter('Second Article','O');
$mpdf->WriteHTML($html);
print $mpdf->Output();

MPDF : independent informations in multiple pages

I actually use MPDF in order to show my HTML code on a PDF.
The problem that I have a lot of payroll employees , and I want to make each payroll on a page.
This code works well.
$html = $this->view->partial('fiche/telechargerfiche.phtml',
array('fichep' => $recuperationFiche));
$mpdf=new mPDF();
foreach ($recuperationFiche as $fiche) {
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->SetHTMLFooter("<div style='text-align: center'><img src='pieddepage.jpg' /></div>") ;
$mpdf->Output();
exit;
But the problem is that my payrolls is shown successively in the same page.
Now I want to make each payroll on an independant page .
I have to use a foreach , but I don't know where is the error , because it's shown to me the same result :
$html = $this->view->partial('fiche/telechargerfiche.phtml',
array('fichep' => $recuperationFiche));
$mpdf=new mPDF();
foreach ($recuperationFiche as $fiche) {
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->SetHTMLFooter("<div style='text-align: center'><img src='pieddepage.jpg' /></div>") ;
$mpdf->Output();
exit;
}
You need to :
Change your partial file to generate the HTML for only one payroll (fiche).
Update your code
Example
$mpdf = new mPDF();
$mpdf->SetDisplayMode('fullpage');
foreach ($recuperationFiche as $i => $fiche) {
if($i) { //If not the first payroll then add a new page
$mpdf->AddPage();
}
$html = $this->view->partial(
'fiche/telechargerfiche.phtml',
array('fichep' => $fiche)
);
$mpdf->WriteHTML($html);
}
$mpdf->SetHTMLFooter( "" );
$mpdf->Output();
exit;
Hope it helps

Categories