GithubHelp home page GithubHelp logo

kartik-v / yii2-mpdf Goto Github PK

View Code? Open in Web Editor NEW
161.0 12.0 150.0 166 KB

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

PHP 9.84% CSS 90.16%

yii2-mpdf's Introduction

Krajee Logo
yii2-mpdf
Donate

Stable Version Unstable Version License Total Downloads Monthly Downloads Daily Downloads

The yii2-mpdf extension is a Yii2 wrapper component for the mPDF library with enhancements. The mPDF library offers ability to generate PDF files from UTF-8 encoded HTML. This library is based on FPDF and HTML2FPDF, with a number of enhancements. The key features in the library are to be able to generate PDF files 'on-the-fly' from HTML content, handling different languages. Refer the documentation manual or the upstream mpdf site for further details and understanding of the library. The yii2-mpdf extension offers an easy way to integrate and use the mPDF library within your Yii application with subtle enhancements. The key features offerred with this release are:

  • Setup pdf component globally in your yii application configuration.
  • Setup mPDF properties or call mPDF methods easily using simple array configuration.
  • Enhances extension to setup your own custom CSS file for rendering the formatted HTML content.
  • Extension has a built-in version of bootstrap.css (v3.3.0 modified for mPDF) to be applied by default. This will allow you to generate PDF content from bootstrap markup HTML easily.
  • Offers easy way to prepend inline CSS in addition to your own CSS file.
  • Offers easy to use object oriented methods to render complex PDF.
  • Easy use of the extension like any Yii widget by using the render method with minimal configuration.
  • The extension uses the latest development version (v6.0beta) of the mPDF library. It uses the composer repository kartik-v/mpdf on packagist as a source for this latest version. mPDF 6.0 can utilise OpenType layout tables to display complex scripts. This release (v6.0) contains fonts (open source) to cover almost every imaginable script / language. Includes support for Arabic or Indic scripts (as well as Khmer, Lao, Myanmar etc.). It also is expected to improve the display of Thai, Vietnamese and Hebrew. It also includes additional fonts for Chinese, Japanese, and Korean.
  • Inbuilt integration with yii2-grid extension that allows you to export grid as PDF and even generate advanced PDF reports.

Demo

Read the detailed documentation and usage of the extension.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require kartik-v/yii2-mpdf "dev-master"

or add

"kartik-v/yii2-mpdf": "dev-master"

to the require section of your composer.json file.

Usage

Widget Like Usage

The component can be used straightforward in a manner similar to any widget to render your HTML content as PDF. For example, you can call the component simply like below in your controller action:

use kartik\mpdf\Pdf;

public function actionReport() {
    // get your HTML raw content without any layouts or scripts
    $content = $this->renderPartial('_reportView');
    
    // 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/src/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(); 
}

Global Component

You can also setup the widget as a global component for use across your application with defaults preset. For example, setup the following in the components section of your Yii application configuration file:

use kartik\mpdf\Pdf;
// ...
'components' => [
    // setup Krajee Pdf component
    'pdf' => [
        'class' => Pdf::classname(),
        'format' => Pdf::FORMAT_A4,
        'orientation' => Pdf::ORIENT_PORTRAIT,
        'destination' => Pdf::DEST_BROWSER,
        // refer settings section for all configuration options
    ]
]

Once you have setup the component, you can refer it across your application easily:

$pdf = Yii::$app->pdf;
$pdf->content = $htmlContent;
return $pdf->render();

For other usage and details, read the detailed documentation.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

yii2-mpdf is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-mpdf's People

Contributors

agnislv avatar daveferger avatar depesr avatar finwe avatar glpzzz avatar hamrak avatar i-lie avatar kartik-v avatar kevinspacey avatar matperez avatar monkeywithacupcake avatar niklaswolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-mpdf's Issues

Options array doesnt pass 'autoScriptToLang', 'autoLangToFont' and possibly 'useAdobeCJK'

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;

Pdf not always generated properly. Garbage in firefox and chrome

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?

Set Header and Footer with two render partials

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

New release

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

Cannot open PDF in Chrome mobile

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

Old mpdf version

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?

Refresh or Redirect after rendering

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.

file_put_contents(.../mpdf/ttfontdata/dejavusanscondensed.GSUBGPOStables.dat): failed to open stream: Permission denied

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?

Font size not increasing.

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');

Cannot generate simple PDF

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

mPDF + amCharts\Highcharts

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.

Https and mpdf

When using http PDF is generated fine and opens quickly.
When using https the formation of the document hangs. Errors any does not show.

Bootstrap classes ignored

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

Localhost Xampp is not working when generate PDF file

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.

'break' not in the 'loop' or 'switch' context

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.

Change the Font Size

I can't change font-size, I am exporting a table with bootstrap style. I set defaultFontSize but is ignored.

Add ability to disable repeating table header row on new page

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

YII2 - PDF - Not showing the latest image.

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

Weird output

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?

DEST_BROWSER shows cached PDF

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();
}

Unable to display elements in grids

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>

PDF result
screenshot- domain - date - time

PHP 7 deprecated warning

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}

Class 'mPDF' not found

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?

print checkboxes

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

Images not showing on production but they do on local environment

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!

Adding some contents to existing PDF file.

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.

QR code in PDF

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-mpdf.
  • This is not an usage question. I confirm having gone through and read the documentation.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

See below

Expected behavior and actual behavior

When I follow those steps, I see...
a "missing image" icon in the PDF

I was expecting...
the QR code

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 2.2.4
  • yii2-mpdf version: dev-master

Isolating the problem

  • This bug happens on the demos page
  • The bug happens consistently across all tested browsers (only Firefox tested)
  • This bug happens when using yii2-mpdf without other plugins.

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 can't install this extension

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

Force Download option

How to add force download option, so if browser have a pdf reader feature, browser still give a download file, not viewing a pdf

update to allow use of Mpdf 7.0 and PHP 7.1.

Steps to reproduce the issue

  1. use a php 7.1 environment
  2. attempt to use the kartik-v/yii2-mpdf library

Expected behavior and actual behavior

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.

Environment

Xampp, PHP 7.1.1

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: irrelevant
  • yii2-mpdf version: dev-master

Isolating the problem

  • This bug happens on the demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-mpdf without other plugins.

Allowed memory size of ... bytes exhausted (tried to allocate 72 bytes)

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.