Yii Framework Forum: Yii2-Mpdf - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2-Mpdf A great PDF component for Yii2 based on the mPDF library. Rate Topic: -----

#1 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 652
  • Joined: 29-August 12

Posted 02 November 2014 - 03:15 PM

This is the forum for the yii2-mpdf extension for Yii framework 2.0. This extension is a great PDF component for Yii2 based on the mPDF library which can convert UTF-8 encoded HTML to PDF with various styling options

Refer documentation and usage.
0

#2 User is offline   kiran nale 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-December 14

Posted 10 December 2014 - 05:13 AM

include(mpdf.php): failed to open stream: No such file or directory
0

#3 User is offline   Juan Alberto 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 06-May 14

Posted 02 October 2015 - 10:53 AM

Hi Kartiv,
We are using the extension to generate a pdf after the app generate a quote.
but we got rare symbols instead of the proper PDF file.

The config file:  
'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
         ],
the controller to call the report:
$pdf = Yii::$app->pdf;
$pdf->mode = Pdf::MODE_UTF8;
$pdf->content = 'Hello Kartik from advanced action';
return $pdf->render();    

Do you have any idea what is going on??
0

#4 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 138
  • Joined: 23-January 12
  • Location:Paris - France

Posted 17 January 2017 - 05:55 AM

I use this extension which works fine.
I have just a problem with checkbox who doesn't appear in the pdf. This checkbox is just to display, operator will check it manually.

My conf:
...
        // setup kartik\mpdf\Pdf component
        $pdf = new Pdf([
            // set to use core fonts only
            'mode' => Pdf::MODE_CORE, 
            // A4 paper format
            'format' => Pdf::FORMAT_A3, 
            // portrait orientation
//            'orientation' => Pdf::ORIENT_PORTRAIT, 
            'orientation' => Pdf::ORIENT_LANDSCAPE, 
            // 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}', 
            'cssInline' => '.tableavecborder{border:1px solid black},
                            .tableavecborder td{height:35px;min-height:35px},
                            .tdcenter{text-align:center}',
             // set mPDF properties on the fly
            'options' => ['title' => 'Dossier de travail ' . $model->document_id],
             // call mPDF methods on the fly
            'methods' => [ 
                'SetHeader'=>[''], 
//                'SetFooter'=>['{PAGENO} / {nbpg}'],
                'SetFooter'=>[''],
            ]
        ]);
...


and the part of the code (inside table)
...
	<input type="checkbox" name="origA4" value="1" checked="" /> A4
...


Thanks for your help.
0

#5 User is offline   Buji Bear 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 17-December 16

Posted 09 March 2017 - 03:36 AM

thanks for sharing
0

#6 User is offline   bravantia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-March 13
  • Location:SPAIN

Posted 13 April 2018 - 06:20 AM

After several days studing the docs and trying to resolve the error that shows a lot of unreadable text in the same page like:

---
%PDF-1.4%����3 0 obj<> /Contents 4 0 R>>endobj4 0 obj<>streamx��S�n�@�������y{�$ !�K] %I�Vy���\�����q��Ti�,�=�uΜ;�׬�R��nfB���K/MT����{��<����JzU�����}�@�F�g[�}(�^ n#>aœƗ�8�9eWf�m|U�bN� ��(�9��W�tNS�]�kb2�HS�W�:�ƪ��Tb��%Ww�a�f]s��Hopj�d�ܶ�^��F�)���7|�KFemR��}@�;��� Q�ۮ�L�8
----

and finishing with:

----
exception 'yii\web\HeadersAlreadySentException' with message 'Headers already sent in [...]vendor\mpdf\mpdf\src\Mpdf.php on line 9356.' in [...]\vendor\yiisoft\yii2\web\Response.php:366
----

I have tested different solutions found in several posts with the same problem, like:

1- exit after the render,
2- if (headers_sent()) {return;},
3- 'utf-8',
4- Add pdf headers before outputing the pdf: Yii::$app->response->format = \yii\web\Response::FORMAT_RAW; Yii::$app->response->headers->add('Content-Type', 'application/pdf');

and none of them works for me (YII2.0.16, PHP5.6.30)...

But the good part is that if I reload the same page in the browser (F5) the pdf is generated properly...

I have installed the robregonm/yii2-pdf to check and I have the same problem...

Any other solutions please?. How to fix HeadersAlreadySentException?. Please, I need a working pdf extension for yii2...

Thanks a lot, and Kartik congratulations for your great extensions!
0

#7 User is offline   newbiedo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 28-June 12

Posted 27 April 2018 - 12:22 PM

View Postbravantia, on 13 April 2018 - 06:20 AM, said:

After several days studing the docs and trying to resolve the error that shows a lot of unreadable text in the same page like:

---
%PDF-1.4%����3 0 obj<> /Contents 4 0 R>>endobj4 0 obj<>streamx��S�n�@�������y{�$ !�K] %I�Vy���\�����q��Ti�,�=�uΜ;�׬�R��nfB���K/MT����{��<����JzU�����}�@�F�g[�}(�^ n#>aœƗ�8�9eWf�m|U�bN� ��(�9��W�tNS�]�kb2�HS�W�:�ƪ��Tb��%Ww�a�f]s��Hopj�d�ܶ�^��F�)���7|�KFemR��}@�;��� Q�ۮ�L�8
----

and finishing with:

----
exception 'yii\web\HeadersAlreadySentException' with message 'Headers already sent in [...]vendor\mpdf\mpdf\src\Mpdf.php on line 9356.' in [...]\vendor\yiisoft\yii2\web\Response.php:366
----

I have tested different solutions found in several posts with the same problem, like:

1- exit after the render,
2- if (headers_sent()) {return;},
3- 'utf-8',
4- Add pdf headers before outputing the pdf: Yii::$app->response->format = \yii\web\Response::FORMAT_RAW; Yii::$app->response->headers->add('Content-Type', 'application/pdf');

and none of them works for me (YII2.0.16, PHP5.6.30)...

But the good part is that if I reload the same page in the browser (F5) the pdf is generated properly...

I have installed the robregonm/yii2-pdf to check and I have the same problem...

Any other solutions please?. How to fix HeadersAlreadySentException?. Please, I need a working pdf extension for yii2...

Thanks a lot, and Kartik congratulations for your great extensions!


I always make sure to use an empty layout, with no html at all when I render these.

<?php echo $content; ?>

0

#8 User is offline   bravantia 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-March 13
  • Location:SPAIN

Posted 01 May 2018 - 01:42 PM

Thank you newbiedo for your answer!
But I have tested this way with an empty layout and this not revolve me the problem...
Several hours later, I found finally the SOLUTION: It was that I placed the link to actionPdf (the action where I use the pdf class) inside the Pjax::begin() and Pjax::end() zone, so:

1. In the controller/actionPdf (pdf as component in my case)
use kartik\mpdf\Pdf;
// This line first 
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;  
// And continue, as component:
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf', ['model' => $model]);
$pdf->filename = 'filename.pdf';
return $pdf->render();


2. In the common/config/main.php:
use kartik\mpdf\Pdf;
'components' => [  
  // N. setup Krajee Pdf component with default values
  'pdf' => [
    'class' => Pdf::classname(),
    'format' => Pdf::FORMAT_A4,
    'orientation' => Pdf::ORIENT_PORTRAIT,
   ...


3. In the view:
Html::a('PDF list', ['pdf']...

And the most important OUTSIDE of the Pjax::begin() and Pjax::end() zone.

This works for me!!!.
Perhaps helps someboby...
0

#9 User is offline   newbiedo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 28-June 12

Posted 02 May 2018 - 03:18 PM

Glad you got it going.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users