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.
Related
I want to display text in center of the page. But, it's not display proper. I used mpdf and i want to display using mpdf in php.
What I tried :
<?php
require_once __DIR__ . '/../bootstrap.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetDisplayMode('fullwidth');
$stylesheet = '<style>' . file_get_contents('example1.css') . '</style>'; // external css
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML('<div id="center">
Hello World
</div>', 2);
$mpdf->Output('filename.pdf');
CSS :
#centrar{
margin:0;
width: 80%;
background-color: #000;
}
body { text-align: center }
Output :
enter image description here
It's display center in first line. I want to display in full page center part.
How to do that? Please help me. Thanks.
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().
I make a php script which gets an url of a website and convert the website to PDF. This works fine with MPDF version 5.7. I want to upgrade my MPDf to version 6.1 because the version interprets the <li> tag better. I update my fonts and now if i try to execute the script I get an empty Page.
New Code:
ob_start();
include(substr($url, 1, strlen($url)-1));
$html=ob_get_contents();
ob_end_clean();
require_once("mpdf61/mpdf.php");
$mpdf = new mPDF('', 'A4', 8,'roboto');
$mpdf->SetFooter('W&T||Seite {PAGENO}');
$mpdf->SetHTMLHeader('<div style="text-align: right;" ><img style="height:50px;" src="/pics/head/e-logow-01-grww-000.png " ></div>');
$mpdf->SetAutoPageBreak(true , 15);
$mpdf->SetTopMargin(30);
$mpdf->AddPage();
$mpdf->list_indent_first_level = 0;
$mpdf->WriteHTML($html);
$mpdf->Output();
Old code:
ob_start();
include(substr($url, 1, strlen($url)-1));
$html=ob_get_contents();
ob_end_clean();
require_once("mpdf57/mpdf.php");
$mpdf = new mPDF('', 'A4', 8,'roboto');
$mpdf->SetFooter('W&T||Seite {PAGENO}');
$mpdf->SetHTMLHeader('<div style="text-align: right;" ><img style="height:50px;" src="/pics/head/e-logow-01-grww-000.png " ></div>');
$mpdf->SetAutoPageBreak(true , 15);
$mpdf->SetTopMargin(30);
$mpdf->AddPage();
$mpdf->list_indent_first_level = 0;
$mpdf->WriteHTML($html);
$mpdf->Output();
it is the same code code with another libary version.
You have to check your PHP version. Check that mpdf is supported or not to your current PHP version.
Look into this change log file and check If any deprecated function you used or not.
https://github.com/mpdf/mpdf/blob/v6.1.0/CHANGELOG.txt
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 ;)
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