It should look like here http://outsource.gestionminute.com/htmltopdf/form/service.html
Highly appreciated for help,
$url = 'http://outsource.gestionminute.com/htmltopdf/form/test.html';
$html = file_get_contents($url);
$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4-L']);
$mpdf->WriteHTML($html);
$mpdf->Output();
Related
Using mpdf in a Scriptcase application:
using mpdf 8.0.0 and php 7.0.22
$mpdf = new \Mpdf\Mpdf(
[
'mode' => 'utf-8',
'format' => 'A4',
'orientation' => 'P'
]
);
$mpdf->setFooter('{PAGENO}');
$mpdf->SetTitle($product_naam);
$mpdf->WriteHTML($content);
} catch (\Mpdf\MpdfException $e)
{
echo $e->getMessage();
}
results in a string $pageno in the footer of my PDF output, instead of giving the page number.
Does anyone have workaround for this issue?
Here is the answer:
define ("PAGE", chr (123). 'PAGENO}', TRUE);
$mpdf->setFooter(PAGE);
Ref: https://forum.scriptcase.com.br/t/resolvido-problema-com-no-pdf/12501
I am using mPDF to save form input data to PDF. For English, it is working fine. Anyone can use this code to save HTML Form data to PDF.
Issue: In order to fulfill my project requirement I need to use the Chinese Language. My current code is not working for that.
Form.html
<form action='processPDF.php' method='post'>
<label for="name">Name</label>
<input name="name" type="text" id="name">
<input type='submit' name='submit' value='Download PDF'>
</form>
processPDF.php
<?php
header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['submit'])) {
if (isset($_POST['name'])) {
$name = $_POST['name'];
} else {
$Larmtid = '';
}
if (!isset($error)) {
ob_start();
?>
<div style="padding:20px;">
<p>Name: <?php
echo $name;
?></p>
</div>
<?php
$body = ob_get_clean();
$body = iconv('UTF-8', 'UTF-8//IGNORE', $body);
$body = iconv('UTF-8', 'UTF-8//TRANSLIT', $body);
include("mpdf/mpdf.php");
$mpdf = new \mPDF('c', 'A4', '', '', 0, 0, 0, 0, 0, 0);
$mpdf->SetAutoFont();
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($body);
$mpdf->Output('SavePDF.pdf', 'D');
}
}
?>
The problem I am having is: In the input field, I typed 怎么用中文说话 and it prints ��������.
If you want to download the source code here is the link to the code
Do not use 'c' as a $mode parameter, that means PDF core fonts only and they do not support chinese characters.
Try '+aCJK' or '-aCJK' instead.
See example – files using chinese font.
My Code is as follow [mpdf v7.0 from composer]
<?php
require_once './vendor/autoload.php';
//report errors
error_reporting(E_ALL);
ini_set("display_errors", 1);
$config = [
'mode' => '+aCJK',
// "allowCJKoverflow" => true,
"autoScriptToLang" => true,
// "allow_charset_conversion" => false,
"autoLangToFont" => true,
];
$mpdf=new \Mpdf\Mpdf($config);
$mpdf->WriteHTML('Hello World 中文');
$mpdf->Output();
This code works fine, you can try it
// We can pass Language code in mpdf config using mode.
<?php
$config = [
'mode' => [LANGUAGE_CODE], // Example: zh-Hans, en, fr etc
];
$mpdf = new \Mpdf\Mpdf($config);
To display Chinese characters correctly, we need to download a fully Chinese support font and place it into a directory, for instance: /app/fonts/yahei.ttf
We can instance it using ConfigVariables and FontVariables:
use Mpdf\Config\ConfigVariables;
use Mpdf\Config\FontVariables;
// Get the default font dirs and append the custom path to it
$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$fontDirs[] = '/app/fonts/';
// Get the default font data and add the yahei font
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$fontData['yahei'] = [
'R' => 'yahei.ttf'
];
$mpdf = new \Mpdf\Mpdf([
'mode' => '+aCJK',
'setAutoTopMargin' => 'stretch',
'setAutoBottomMargin' => 'stretch',
'default_font' => 'yahei',
"autoScriptToLang" => true,
"autoLangToFont" => true,
'fontDir' => $fontDirs,
'fontdata' => $fontData,
]);
Now you can display Chinese characters
I am working in codeigniter.I have downloaded TCPDF for creating pdf. I have followed all step for generating pdf in codeigniter.
My controller is:
function list_branch_report()
{
if($this->input->post('submit'))
{
$this->load->library('Pdf');
$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Pdf Example');
$pdf->SetHeaderMargin(30);
$pdf->SetTopMargin(20);
$pdf->setFooterMargin(20);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('Author');
$pdf->SetDisplayMode('real', 'default');
$pdf->Write(5, 'CodeIgniter TCPDF Integration');
$pdf->AddPage();
$pdf->Output('pdfexample.pdf', 'I');
$branch_id = $this->input->post('br_name');
$branch_code = $this->input->post('branch_code');
$query1 = $this->db->query("select * from branch_bal where branch_id = '$branch_id'");
$result1 = $query1->result();
$query2 = $this->db->query("select * from cash_depo where bid = '$branch_id'");
$result2 = $query2->result();
$this->load->view("admin/list_branch_report",array('br_result'=>$result1,'cash_result'=>$result2,'b_code'=>$branch_code));
}
And my view page is:
<div style="float:left;width:100%">
<center><h1> Branch Report </h1></center>
</div>
When I try to generate pdf then it will display blank.
where are you writing HTML to PDF I haven't work on tcpdf but as my experience with mpdf as far as i know
there should a function like
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
please refer tcpdf documentation for writeHTML() or writeHTMLCell() functions
http://www.tcpdf.org/doc/code/classTCPDF.html
or refer examples
http://www.tcpdf.org/examples.php
you have to assign codeigniter view to variable for that give last attribute as true
$html= $this->load->view("admin/list_branch_report",array('br_result'=>$result1,'cash_result'=>$result2,'b_code'=>$branch_code),true);
and then assign this to
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
I have written ob_start(); before the load view page.Then i have written
$html = $this->load->view("admin/list_branch_report",array('br_result'=>$result1,'cash_result'=>$result2,'b_code'=>$branch_code),true);
$pdf->writeHTML($html, true, false, true, false, '');
ob_clean();
$pdf->Output();
this code.
So it works perfect.
Thanks to all.
use mpdf instead of tpdf and send html that you want to convert in pdf.
In my function have added the following codes in mpdf->confing_cp.php
CASE "meera": $unifonts = "meera,meeraI"; break;
also Added the following code in mpdf->config_font.php
"meera" => array(
'R' => "Meera.ttf",
),
And in my controller i need the lanscape view also ,so following are the codes in my controller to generte pdf
`
function export_pdf() {
$this->data['admin_page_title'] = 'Script';
$this->data['portrite'] = $this->input->post('formate');
this->data['script_pdf']=$this->Script_model->get_selected();
ini_set('memory_limit','250M');
$html = $this->load->view('admin/script/pdf_view', $this->data,true);
//include_once APPPATH.'/third_party/mpdf/mpdf.php';
$this->load->library('pdf');
$pdf = $this->pdf->load();
$pdf = new mPDF('ml', 'A4');
$pdf->AddFont('meera','','meera.ttf',true);
$pdf->SetFont('meera','',14);
if($this->data['portrite']=="landscape") {
$pdf=new mPDF('utf-8', 'A4-L');
}
// $pdf->SetAutoFont(AUTOFONT_ALL);
// $pdf->setHTMLFooter($footer);
$pdf->WriteHTML($html);
$pdf->Output();
exit;`
}`
Hello my task is to certify pdf with digital Signature Certification and release it in pdf/a format. I tried using tcpdf, but i couldn't import existing pages. So I added fpdi, kind of mixing them:
require_once('./tcpdf/tcpdf.php');
require_once('./tcpdf/fpdi.php');
$pdf = new FPDI( );
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
$file = realpath("484.pdf");
$pagecount = $pdf->setSourceFile($file);
for($i = 1 ; $i <= $pagecount ; $i++){
$tpl = $pdf->importPage($i);
$size = $pdf->getTemplateSize($tpl);
$orientation = $size['h'] > $size['w'] ? 'P':'L';
$pdf->AddPage($orientation);
$pdf->useTemplate($tpl, null, null, $size['w'], $size['h'], true);
}
$pdf->SetCreator("Creator");
$pdf->SetTitle('123Titel');
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$certificate = 'file://123.crt';
$info = array(
'Name' => '123test',
'Location' => 'place',
'Reason' => '123',
'ContactInfo' => '123',
);
$pdf->setSignature($certificate, $certificate, '123', '', 2, $info);
$pdf->SetFont('helvetica', '', 12);
$pdf->addEmptySignatureAppearance(0, 0, 0, 0);
$pdf->Output('test.pdf', 'F');
Alright, so I can put signature in alright with this, but i cant make it pdf/a.
What decides pdf/a format is
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
The last "true". But I cant use this tcpdf function, or i get:
Call to undefined method TCPDF::setSourceFile() in...
So im forced to use $pdf = new FPDI( );, which can't save pdf in pdf/a format
Surely someone knows something that im missing and im running out of ideas on what to do.
-Can I import existing pdf with only tcpdf and if yes HOW?
-Is there any other way to make file format pdf/a (i coudlnt find any)
-Any tips whatsoever
It appears that I can extend tcpdf with fpdi. Somehow it didnt work until i changed fpdi_bridge to always extend tcpdf and changed
new FPDI();
to
new FPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);