kartik-v / yii2-mpdf Goto Github PK
View Code? Open in Web Editor NEWA Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
Home Page: http://demos.krajee.com/mpdf
License: Other
A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
Home Page: http://demos.krajee.com/mpdf
License: Other
Tried to use this extension. Generating a pdf file with destination 'D' works fine. But with destination 'I' the output is not always a pdf document but some kind of garbage with lots of non displayable charaters.
Only windows explorer has no problem to show the generated output as a pfd document.
The strange thing is that it works sometimes correct. As an example:
Using a DetailView::widget, which includes all fields from the model, works fine. But commenting out some of the fields the garbage will be produced. Commenting out other fields makes no trouble.
I could't find out any rule for this behaviour.
Just an idea: You're using the beta version 6 of mpdf. Could this be the source of trouble?
Can you please let me know how to use the actual version of mpdf with this extension?
Yii 2.0.6
PHP 5.4.7
Linux mint 17.2
CONTROLLER:
public function actionReporteProgramaPdf()
{
// get your HTML raw content without any layouts or scripts
$content = $this->renderPartial('reporteProgramaPdf');
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// LETTER paper format
'format' => Pdf::FORMAT_LETTER,
// 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:18px}',
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['Krajee Report Header'],
'SetFooter'=>['{PAGENO}'],
]
]);
// return the pdf output as per the destination setting
return $pdf->render();
}
VIEW:
<?php
echo'INFORMACIÓN';
?>
RESULT:
%PDF-1.4 %���� 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream x��R�N�0����7���N����-�Q�6��b�hZTQ���������/E*�C�䒻�|�l!�����+&�M����n�r/r,��<�`� ���fK\f�������f���z��b�軂=�4� ���o endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> endobj 9 0 obj <> endobj 2 0 obj <> /ExtGState << /GS1 5 0 R >> >> endobj 10 0 obj << /Producer (��mPDF 6.0) /Title (��Krajee Report Title) /CreationDate (20151013165316+02'00') /ModDate (20151013165316+02'00') >> endobj 11 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /XYZ null null 1] /PageLayout /OneColumn >> endobj xref 0 12 0000000000 65535 f 0000000648 00000 n 0000001201 00000 n 0000000015 00000 n 0000000223 00000 n 0000000737 00000 n 0000000798 00000 n 0000000896 00000 n 0000000992 00000 n 0000001093 00000 n 0000001347 00000 n 0000001521 00000 n trailer << /Size 12 /Root 11 0 R /Info 10 0 R /ID [ ] >> startxref 1631 %%EOF
Hi,
Is there a way to combine/merge several PDF/DOC/DOCX files into one PDF file and then render the PDF file for download?
Or is there any possible way to integrate mpdf with pdftk?
Thank you.
Kind regards.
After upgraded to php 7, this deprecated warning is issued:
PHP Deprecated Warning 'yii\base\ErrorException' with message 'Methods with the same name as their class will not be constructors in a future version of PHP; mPDF has a deprecated constructor' in \vendor\kartik-v\mpdf\mpdf.php:89 Stack trace: #0 {main}
Hello. I need to print an invoice , with the header and footer as views. This is my code
$content = $this->renderPartial('_pdf-conceptos', [
'model' => $model,
'dataProviderConceptos' => $dataProviderConceptos,
'dataProviderTributos' => $dataProviderTributos,
]);
$heading = $this->renderPartial('_pdf-heading', [
'model' => $model,
'dataProviderConceptos' => $dataProviderConceptos,
'dataProviderTributos' => $dataProviderTributos,
]);
//return $this->render('pruebaPDF', ['coso' => $heading . $content]);
// return $this->render('_pdf-conceptos', [
// 'model' => $model,
// 'dataProviderConceptos' => $dataProviderConceptos,
// 'dataProviderTributos' => $dataProviderTributos,
// ]);
//
// 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:18px}',
// set mPDF properties on the fly
'options' => ['title' => 'Ver Recibo'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>$heading,
'SetFooter'=>['{PAGENO}'],
]
]);
// return the pdf output as per the destination setting
return $pdf->render();
If the heading and content i render into a view the invoice is well formed. How can I do this
PHP Version 7.0.4
There is an error in \vendor\kartik-v\mpdf\classes\svg.php on line 2710 when generating a PDF with SVG files in it.
'break' not in the 'loop' or 'switch' context.
Replacing the "break" with "return" seems to work as a temporary fix.
master
branch of yii2-mpdf.See below
When I follow those steps, I see...
a "missing image" icon in the PDF
I was expecting...
the QR code
I'm using your PDF extension and the QR-Code extension from 2amigos. The issue I run into is the following:
In my view _pdf
I "include" the QR code by <img src="<?= Url::to(['route/qrcode','text'=>$model->qr_code_content]) ?>" />
In my Controller I have this function
public function actionQrcode($text){
Yii::$app->response->format = Response::FORMAT_RAW;
Yii::$app->response->headers->set('Content-Type','image/png');
return QrCode::png($text)
}
The Controller renders the view in the actionPdf
public function actionPdf($id) {
$model = $this->findModel($id);
#return $this->renderPartial('_pdf', ['model' => $model]);
$content = $this->renderPartial('_pdf', ['model' => $model]);
$pdf = new Pdf([
'content' => $content,
'filename' => 'Ticket_' . $model->id . '.pdf',
'options' => [
'title' => 'Your ticket as '
],
'cssFile' => '@webroot/css/pdf.css'
]);
$pdf->render();
}
In the PDF the QR code is displayed as "missing image" icon, if I uncomment the third line (return $this->renderPartial(...
the page renders as normal HTML and the QR code is displayed correctly.
I will also open an issue for the mpdf extension. Please look up the issue together with 2amigos, thx
See also my comment on the issue in the 2amigos/yii2-qrcode-helper repo
I noticed that mpdf version is quite old.
Maybe you could add row to composer.json, that it requires original mpdf package and make realease?
Hello there!
I just want to know how will I issue $this->refresh() or redirect after rendering my pdf? Thank you in advance for the reply.
When using http PDF is generated fine and opens quickly.
When using https the formation of the document hangs. Errors any does not show.
How to remove the boder-bottom of the header
Hey,
What should I do to include all my css files of my main layout in my pdf ?
Thank you.
Hi,
Can someone help me please, i'm trying to print a pdf with checkboxes but its not working, only the labels are shown in the document.
PD: sorry for my poor english
Hello
After installing "kartik-v/yii2-mpdf": "dev-master" last versions, I have this out put:
`
header("Content-type:application/pdf");
$content = $this->renderPartial('_park_pdf');
$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,
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
]);
// return the pdf output as per the destination setting
return $pdf->render();`
https://db.tt/A3MWGJLgWf
Is it good output?
Following new property added to kartik\mpdf\Pdf
class.
/**
* @var string the folder path for storing the temporary data generated by mpdf.
* If not set this defaults to `Yii::$app->getAlias('@app/runtime/mpdf');`.
*/
public $tempPath;
Hello.
Localhost Xampp is not working when generate PDF file.
It is working on the server, but it doesn't work on local xampp server.
Is there more configuration on this project to satisfy local environment?
Thank you.
Could you create a new release and refresh it on packagist? Currently stable is at 1.0.0 which still uses your old mpdf fork.
I would like to avoid relying on dev-master if it all possible.
Thanks
Hi,
I'm a newbie with Yii, and I'm beginning a project with that framework by a petition.
I need to generate some reports in PDF, and I try to install this extension with composer using this code:
php composer.phar require kartik-v/yii2-mpdf "dev-master"
But when composer starts the download, gives a message error, like that:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package kartik-v/yii2-mpdf could not be found in any version, there may be a typo in the package name.
Could you give me some help with that?
Thanks,
PD: Sorry for my bad English
I can't change font-size, I am exporting a table with bootstrap style. I set defaultFontSize but is ignored.
Hello.
I have got very long PDF document, but I want to change only one page from that one.
I want to create new page and merge into existing pdf, but no luck yet.
I used below function in mPDF, but I want to know if i can do below functionality with this yii2-mpdf.
private function merge_PDFs( $files, $path ){
$pdf = new mPDF('', '', 0, '', 15, 15, 6, 12, 9, 9, 'P');
$pdf->enableImports = true;
foreach( $files as $file ){
$pdf->SetImportUse();
$pagecount = $pdf->SetSourceFile($file);
for ($i=1; $i<=($pagecount); $i++) {
$pdf->AddPage();
$import_page = $pdf->ImportPage($i);
$pdf->UseTemplate($import_page);
}
}
$pdf_name = date('Y-m-d_His') . '.pdf';
$pdf_path = $path . $pdf_name;
//Make sure path exists
if (!file_exists($path)) {
mkdir($path, 0777);
}
$pdf->Output($pdf_path, 'F');
unset($pdf);
return $pdf_path;
}
I only need to change few contents on very long PDF file, but I can not find good solution with this yii2-mpdf.
If you someone helps me, then I will be very appreciate at that.
Thank you.
When I follow those steps, I see a whole bunch of errors because mpdf 6 does not support PHP 7.1.X and yii-mpdf does not support a higher version of mpdf. It works fine if I just use the mpdf library to export simple pages but when used in combination of other elements (such as the GridView widget it throws an error.
`Invalid Configuration – yii\base\InvalidConfigException
The class '\kartik\mpdf\Pdf' was not found and is required for PDF export functionality. To include PDF export, follow the install steps below. If you do not need PDF export functionality, do not include 'PDF' as a format in the 'export' property. You can otherwise set 'export' to 'false' to disable all export functionality.
Please ensure you have installed the 'yii2-mpdf' extension. To install, you can run this console command from your application root:
php composer.phar require kartik-v/yii2-mpdf: "@dev"`
Your wrapper should be updated to support the new PHP versions as well as the latest Mpdf version. Please update.
Xampp, PHP 7.1.1
Could you consider update to 7th version? Mpdfs maintainers aren't going to support 6th version for php 7.1. mpdf/mpdf#288
Hello @kartik-v ,
Good job on this extension, I have a requirement for help, the JavaScript is the problem..
The other day I logged into a private platform, and it was running PHP, I have no clue what Framework whatsoever, whht I do know is that it was generating PDF reports on the fly, with HighCharts graphs as images in the PDF.
Now, I myself use amCharts, but even looking at Highcharts, I have no clue, how can this be made.
Is this remotely possible? Am I missing something? Even if it's not a pretty solution.. How would one?
amCharts generate grpahs as images, yes, but he needs to render the page first to run the JavaScript, so how can one export a JS graph as an image, to a PDF? In the controller?
Thanks for your input.
Hello,
I try to create pdf file:
...
foreach ($models as $model) {
$table .= Html::beginTag('tr');
$table .= Html::tag('td', urldecode($model->var1));
$table .= Html::tag('td', date('Y-m-d', $model->date));
$table .= Html::tag('td', $model->var2);
$table .= Html::endTag('tr');
}
...
echo strlen($table) // strlen($table) is 8153
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_LANDSCAPE,
'destination' => Pdf::DEST_BROWSER,
'content' => $table,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline' => '.kv-heading-1{font-size:18px}',
'options' => ['title' => 'Krajee Report Title'],
'methods' => [
'SetHeader'=>['header'],
'SetFooter'=>['{PAGENO}'],
]
]);
// Yii::$app->response->sendContentAsFile($pdf->render(), 'my-report.pdf', ['mimeType' => 'application/pdf']);
$pdf->render(); // Allowed memory size of 1073741824 bytes exhausted (tried to allocate 72 bytes)
if i remove '$pdf->render();' line, error does not occur
Bootstrap glyphicons aren't visible in print version.
In print version shows nothing
When i am generating pdf, font style is too small, we can not read in that font size. My code is below.
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
// 'cssFile' => '@web/css/kv-mpdf-bootstrap.min.css',
// 'cssInline' => '.table{font-size:28px}',
]);
$mpdf = $pdf->api;
$mpdf->WriteHtml($content);
return $mpdf->Output('test.pdf', 'D');
In vendor/kartik-v/yii2-mpdf/Pdf.php line 281, it reads
public function output($content = '', $file = '', $dest = self::DEST_INLINE)
results in error self::DEST_INLINE is not defined.
Recommend changing line 281 to be
public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
How do I add a path to destination?
'destination' => Pdf::DEST_FILE,
We have troubles because doesn't correctly display the grids
Controller
public function actionPdfMif($idimpianto) {
$impianto = $this->findModel($idimpianto);
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_LANDSCAPE,
'destination' => Pdf::DEST_BROWSER,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/bootstrap.min.css',
'content' => $this->renderPartial('_pdf-mif'),
'options' => ['title' => 'Krajee Report Title'],
'methods' => [
'SetHeader' => ['MIF '.$impianto->titolo_pagina],
'SetFooter' => ['{PAGENO}'],
],
'destination' => Pdf::DEST_DOWNLOAD,
'filename' => 'MIF-'.$impianto->codice_separato.".pdf",
]);
return $pdf->render();
}
View
<div class="container">
<div class="row">
<div class="col-xs-12" style="background-color: red">12</div>
</div>
<div class="row">
<div class="col-xs-6" style="background-color: yellow">6</div>
<div class="col-xs-6" style="background-color: yellow">6</div>
</div>
<div class="row">
<div class="col-xs-4" style="background-color: lightskyblue">4</div>
<div class="col-xs-4" style="background-color: lightskyblue">4</div>
<div class="col-xs-4" style="background-color: lightskyblue">4</div>
</div>
<div class="row">
<div class="col-xs-3" style="background-color: greenyellow">3</div>
<div class="col-xs-3" style="background-color: greenyellow">3</div>
<div class="col-xs-3" style="background-color: greenyellow">3</div>
<div class="col-xs-3" style="background-color: greenyellow">3</div>
</div>
<div class="row">
<div class="col-xs-2" style="background-color: whitesmoke">2</div>
<div class="col-xs-2" style="background-color: whitesmoke">2</div>
<div class="col-xs-2" style="background-color: whitesmoke">2</div>
<div class="col-xs-2" style="background-color: whitesmoke">2</div>
<div class="col-xs-2" style="background-color: whitesmoke">2</div>
<div class="col-xs-2" style="background-color: whitesmoke">2</div>
</div>
<div class="row">
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
<div class="col-xs-1" style="background-color: pink">1</div>
</div>
</div>
Hello, I have a couple of simple PNG images in a view print.php, like this:
<img src="<?= \yii\helpers\Url::to('@web/images/logo.png') ?>" width="100" alt="logo" />
In the local environment, the images shows fine in the generated PDF and even if I just print it without PDF (controller code):
return $this->renderPartial('print', [
'model' => $this->findModel($id),
]);
However, on the production server, the images are not showing. They show only if I print the view without PDF (like in the previous code), so for me this means that the images are fine, no broken links (because they show on renderPartial) and leads me to think that there might be some issue with the mpdf?
The generated PDF in the production server shows a red "X" where the image should be loaded. How can I troubleshoot this? Can the PDF be examined? If it was an HTML page I would check where the link in "src" is leading, but in the PDF I'm not sure how to proceed.
Local environment is PHP 5.5 and production is PHP 5.6. Does this has something to do?
Any help will be really welcomed and appreciated!
This in web.php config file under 'compenets'
'pdf' => [
'class' => Pdf::classname(),
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_STRING,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'options' =>[
'autoScriptToLang' => true,
'autoLangToFont' => true,
'useAdobeCJK' => true,
]
]
didnt work, had to
$pdf = Yii::$app->pdf;
$mpdf = $pdf->api;
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->useAdobeCJK = true;
The mpdf default always repating table header on a new page, but sometimes we need to disable this in mpdf documentation this feature should be affected, but in fact is not
I try to use
'tableOptions'=>[
'class' => 'table table-bordered table-condensed',
'repeat_header' => 0, // or 1
],
Still not affected
I think this options is can enable from grid/export(mpdf) options
How to add force download option, so if browser have a pdf reader feature, browser still give a download file, not viewing a pdf
New constant Pdf::MODE_ASIAN
added to quick set the mPDF mode for Asian fonts.
I'm getting Illegal string offset 'ID' after upgrading to PHP 7.1 is there a workaround for this?
vendor/mpdf/mpdf/classes/cssmgr.php
who to get water mark Image?
$pdf->getApi()->SetWatermarkImage('image link');
In my yii2 project, i'm using kartik\mpdf\Pdf to prepare pdf report. In the application it is not showing the latest image from database and shows only old image. following is the code i made.<?= Html::img(\Yii::$app->urlManager->createUrl(['/site/loadheader', 'id' => $img->COMPANYCODE]),array('width'=>1024,'height'=>174,'alt'=>'Header')); ?>
in the controller i made the following code:-` public function actionPrint($id)
{
// get your HTML raw content without any layouts or scripts
$content = $this->renderPartial('_print',['id' => $id]);
// 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:18px} ' .
'.tbl {border: 1px solid black; border-collapse: collapse} ' .
'.tbl-horiz {border-left: 1px solid black; border-right: 1px solid black;} ',
// set mPDF properties on the fly
'options' => ['title' => ''],
// call mPDF methods on the fly
//'methods' => [
// 'SetHeader'=>[''],
// 'SetFooter'=>['{PAGENO}'],
//]
]);
// return the pdf output as per the destination setting
return $pdf->render();
}
`
friends, please go through this and give me a solution....
Getting an error for: "Methods with the same name as their constructor class will not be constructors in a future version of PHP"
I'm using mPDF inmy action like this:
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $output,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline' => '.kv-heading-1{font-size:18px}',
'options' => ['title' => 'My report ' . date("Y/m/d", time())],
'methods' => [
'SetHeader'=>['My report ' . date("Y/m/d", time())],
'SetFooter'=>['{PAGENO}'],
]
]);
return $pdf->render();
and I receive the exception:
file_put_contents(/home/iam/git/superproject/application/vendor/kartik-v/mpdf/ttfontdata/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: Permission denied
How can I solve this trouble?
Hi, thank you for your great work!
I'm trying to generate a pdf from a model, formatting the html with bootstrap 3 classes but the system seems to completely ignore them.
Here is my rendered view:
<div class="fattura-view container">
<div class="row">
<div class="col-lg-6">
<h3>Fattura N. <?= $model->anno;?>/<?= $model->id_anno;?> del <?= $model->data_emissione;?></h3>
<p>
Pagamento: <?= $model->termini_pagamento;?> Data scadenza: <?= $model->data_scadenza;?>
UBI Banca Popolare di Bergamo fil. Loreto (BG)<br />
IBAN: IT97G0542811109000000000983 - SWIFT: BEPOIT21
</p>
</div>
<div class="col-lg-6">
<h3><?= $model->cliente->ragione_sociale?></h3>
<p>
<?= $model->indirizzo;?> - <?= $model->cap;?> - <?= $model->citta;?> - <?= $model->provincia;?><br />
P.iva:<?= $model->partita_iva;?> / Codice Fiscale: <?= $model->codice_fiscale;?>
</p>
</div>
</div>
</div>
and here is my action in controller
public function actionStampaFattura($id) {
// get your HTML raw content without any layouts or scripts
$model = Fattura::findOne($id);
$content = $this->renderPartial('view', array('model'=>$model));
// 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:18px}',
// set mPDF properties on the fly
'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['Krajee Report Header'],
'SetFooter'=>['{PAGENO}'],
]
]);
// return the pdf output as per the destination setting
return $pdf->render();
}
Thank you
Alessandro
How can i automatic open print dialog ?
Thanks
Initialize certain default options for mPDF to generate PDF better with varied content.
public $options = [
'autoScriptToLang' => true,
'ignore_invalid_utf8' => true,
'tabSpaces' => 4
];
Hi, @kartik-v !
How can i set charset encoding in the pdf output file? For example, windows-1251
If the return is
return $pdf->render();
There seems to be a cache-related problem (tested in Chrome 48, Opera 35 and IE 11) when using mpdf with destination DEST_BROWSER. The PDF file that opens in the browser doesn't get re-generated from the current view, but shows the previous PDF that was generated for the view - until I manually hit refresh in the browser tab that contains said PDF. This does not happen when destination is DEST_DOWNLOAD, it always reflects the current state of the view in question.
Here's my setup:
Relevant Yii2 packages:
mPDF 6.0 (20/12/2014)
yii2-mpdf 1.0.0
View:
<?= Html::a('<i class="fa fa-print"></i> Print', ['/projects/project-print', 'id' => $model->id], [
'class'=>'btn btn-default',
'target'=>'_blank',
]); ?>
Projects Controller:
public function actionProjectPrint() {
$id = $_GET['id'];
$pdfContent = Yii::$app->runAction('projects/printView', ['id' => $id]);
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'marginTop' => 45,
'marginHeader' => 9,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $pdfContent,
'cssFile' => './css/mpdf_bootstrap.css',
'options' => ['title' => 'Test'],
'methods' => [
'SetFooter'=>['{PAGENO}'],
]
]);
return $pdf->render();
}
I just installed this extension via composer and got this error when trying to use it:
PHP Fatal Error – yii\base\ErrorException: Class 'mPDF' not found
in /opt/lampp/htdocs/basic/vendor/kartik-v/yii2-mpdf/Pdf.php at line 201
yii2-mpdf & mpdf are already in /vendor/kartik-v directory and yii2-mpdf has been added to extensions.php. Am I missing something here?
I tried using this project's custom bootstrap file to see if this would resolve the same problem documented by the following two link where the col-xs-# class moves to the next line:
Got any suggestions on how to resolve this issue?
Configuration:
'pdf' => [
'class' => Pdf::classname(),
'format' => Pdf::FORMAT_LETTER,
'orientation' => Pdf::ORIENT_LANDSCAPE,
'destination' => Pdf::DEST_BROWSER,
'cssFile' => '@webroot/css/document.css',
'marginTop' => 10,
],
Controller:
$pdf = Yii::$app->pdf;
$pdf->methods = ['SetFooter' => ['{PAGENO}']];
$pdf->content = $this->renderpartial('_tracker', [
'year' => $year,
'customer' => $models['customer'],
'totals' => $models['totals']
]);
$pdf->filename = 'Tracker.pdf';
return Yii::$app->pdf->render();
The script above works well in desktop browsers (Chrome, Opera, Firefox, IE) and mobile browsers (Firefox, Opera). However, it showed an error when I opened the page using Chrome mobile (Android):
Cannot display PDF (index.php is of invalid format)
Could this be related to Google Drive PDF Viewer issue (https://productforums.google.com/forum/#!topic/drive/xkkVSoLSIxo;context-place=topicsearchin/drive/category$3Adrive-mobile-app%7Csort:relevance%7Cspell:false)? I opened the mPDF demo page (http://demos.krajee.com/site/mpdf#demo) and it was displayed properly on Chrome mobile. Did I make a mistake in the configuration?
Yii: 2.0.9
Chrome mobile: 52.0.2743.98
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.