I'm currently working on making the correct version of language dependent glyphs show up in their respective PDF files... From what I understand after reading through the mPDF documentation is that all I need to do is to set the the html lang value like below and to set autoScriptToLang and autoLangToFont to true
Example html where I want the Japanese version of the characters:
<html lang="ja">
<body>
Sample language-dependent glyphs: 直今令角雇
</body>
</html>
And yet it doesn't seem to reflect on the PDF file that is generated.
Here's the settings I'm passing over to Mpdf\Mpdf
$settings = [
'autoLangToFont' => true,
'autoScriptToLang' => true,
'format' => 'A4',
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 10,
'margin_bottom' => 20,
'margin_header' => 0,
'margin_footer' => 5,
'tempDir' => '/tmp/',
'default_font' => 'frutiger'
];
I tried displaying the HTML I'm passing over to mPDF and it works there, so I believe my issue is that I'm missing a setting to allow mPDF to display the Japanese versions of those characters.
Related
I have a mPDF instance, in which I override the font directory and fontdata with an empty array .
What I want to achieve is that when I add HTML, which has a font-family that is not configured within my font arrays, an error is thrown. Now it automatically falls back on a font which is manually added.
mPDF instantiation
$config = [
'mode' => 'utf-8',
'format' => 'A4',
'author' => 'John Doe',
'creator' => 'John',
'default_font_size' => 12,
'default_font' => '',
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
'margin_header' => 0,
'margin_footer' => 0,
'orientation' => 'P',
'fontDir' => [], // Don't use fallback font dir.
'fontdata' => [], // Don't use fallback fontdata
$mpdf = new Mpdf($config);
Manually adding Roboto
$config['fontDir'] = array_merge($config['fontDir'], ['path/to/my/custom/roboto/font']
$config['fontdata'] = array_merge(config['fontdata'], [
'roboto' => [
'R' => 'Roboto-Regular.ttf',
],
];
Desired Result
The problem which occurs to me is that when I do the following:
$mpdf->WriteHTML('<body style="font-family: Lato">Hello world!</body>');
mPDf automatically uses my manually added Roboto as fallback font. But I would love to know if there is a way in which I can let mPDF throw an error in which it states that the font Lato is not configured within its font-data.
I really hope you guys can help me out!
Kind Regards.
This currently cannot be done with mPDF – it will always select a suitable substitution font as a browser would do.
The process of selecting a substitute is described in the documentation.
I am generating a PDF and it will create a white space between content.
example
When I output the same content just in HTML it will not, so I don't think it's the HTML or CSS; however, something on generating a PDF is creating that small gap, and I can't for the life of me figure it out.
I am hoping it's just a wkhtmltopdf setting, but I have been through all of them.
I am setting them in PHP like this:
return [
'page-size' => 'A4',
'page-height' => $height,
'page-width' => $width,
'dpi' => 96,
'margin-left' => 0,
'margin-right' => 0,
'margin-top' => 0,
'margin-bottom' => 0,
'disable-smart-shrinking' => true,
'load-media-error-handling' => 'abort'
];
I have added the page-size in an attempt to solve it, but it did not work.
We have a website that is currently on an Ubuntu 16.04 server and we are working on moving to Amazon. The rest of the site (Written in PHP Yii 1.1) is working fine except for the piece that present our reports in PDF format.
The report is written to pdf with no real issue but images show as a red X After some debugging I came to the conclusion that the majority of the images are png images and that is why they do not show. The single jpg image on the report is showing.
How can I get this to work? The html version of the report (that uses different code) gets the image from the same place and that works just fine. I cannot really convert all images because they are generated dynamically.
I read somewhere that pdf does not support png images, REALLY?? Why did it render just fine on the current server?
I do not believe that is is going to help but here is some code used:
main.config:
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendors.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)
),
),
Controller:
$mPDF1 = Yii::app()->ePdf->mpdf('utf-8', 'A4');
$mPDF1->simpleTables = true;
$mPDF1->useSubstitutions = false;
$mPDF1->WriteHTML($this->renderPartial('pdfRXMapFile', array('model' => $model)));
I have a problem with position of qrcode in tcpdf.
First, I want a output of qrcode like this:
but after I added many rows inside of table, qrcode position doesn't follow with my table, like a picture below.
And this is my code
$style = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,Q', 0, 143, 50, 30, $style, 'N');
Please help me, what must I do with this problem.
With gladness, I say thank you for your help.
I have a problem to generate many pages (more of 5,000 pages) with PHP. In real, the problem is a time of wait to generate.
I am use the framework YII 2.0 and the widget mPDF, to generate 60 pages the time of wait its from 2mins.. I have to otimize this time, but its necessary generate the pdf (with css to style the doc)..
I understand to generate more of 5,000 pages it will take a while, but i need otimize the maximum this time, the way it is now It is too long.
Anyone know the way to do this? Not necessary need to use YII, if have other way with PHP (library, or some way else).
Code:
$content = $this->renderPartial('tabela-pdf', [
'model' => $model,
'table' => $table, //CONTENT
]);
$header = $this->renderPartial('pdf');
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
'cssInline' => '.kv-heading-1{font-size:14px}',
// set mPDF properties on the fly
'options' => ['title' => 'Relatório'],
'defaultFontSize' => 3,
'marginLeft' => 10,
'marginRight' => 10,
'marginTop' => 30,
'marginBottom' => 11,
'marginHeader' => 6,
'marginFooter' => 6,
// call mPDF methods on the fly
'methods' => [
'SetHeader' => [$header],
'SetFooter' => ['<p style="text-align: center;font-size: 8px;">FOOTER</p>'],
]
]);
$pdfName = 'FILE-_' . date('d-m-Y') . '.pdf';
Yii::$app->response->format = Response::FORMAT_HTML;
Yii::$app->response->setDownloadHeaders($pdfName, 'application/pdf');
return $pdf->render();
Just a document with a big table (no have identical content)