2

Working with Yii framework 2, I use kartik\mpdf\Pdf class to response my HTML page in PDF format to the browser. Below is my configuration.

$pdf = new kartik\mpdf\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' => $htmlContent,  
                // 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} .page-break{ page-break-after:always; } li { list-style:none; }', 
                 // set mPDF properties on the fly
                'options' => ['title' => 'My title'],
                 // call mPDF methods on the fly
                'methods' => [ 
                    'SetHeader'=>['My_header_ ' . date('d-m-Y')], 
                    'SetFooter'=>['{PAGENO}'],
                ],
 ]);

 // return the pdf output as per the destination setting
 return $pdf->render(); 

Everything works perfectly, except when there is a variable inside my HTML page, which returns a long string, that text becomes small. How can I solve it?

O Connor
  • 4,236
  • 15
  • 50
  • 91
  • What is your HTML? Does it contain a table? – Finwe Aug 23 '16 at 20:29
  • Yes the long string lives in a cell table, thus the font size of the whole table becomes smaller. I am using DIV instead, just solve it for now. But still want to find solution in case I want to work with table. – O Connor Aug 24 '16 at 02:23
  • @OConnor similar kind of issue already posted by some one and I answered the solution there. Please check. It may help - http://stackoverflow.com/questions/26179403/how-to-prevent-table-resizing-in-pdf-using-mpdf-and-php – Manikandan S Apr 27 '17 at 12:04

1 Answers1

2

mPDF resizes too large tables to fit a page. To prevent this, either add

'options' => ['shrink_tables_to_fit' => 0];

to your kartik\mpdf\Pdf constructor call OR set a custom HTML attribute

<table autosize="0">

Also see mPDF manual on tables.

Finwe
  • 6,372
  • 2
  • 29
  • 44