Yii framework 2 kartik/mpdf 中的文本太长时字体会变小。如何解决?

Font size becomes small when the text is too long in kartik/mpdf of Yii framework 2. How to fix that?

使用 Yii 框架 2,我使用 kartik\mpdf\Pdf class 将我的 HTML 页面以 PDF 格式响应到浏览器。下面是我的配置。

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

一切正常,除了我的 HTML 页面中有一个变量,returns 一个长字符串,该文本变小。我该如何解决?

mPDF 调整过大的表格以适应页面。为了防止这种情况,要么添加

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

到您的 kartik\mpdf\Pdf 构造函数调用或设置自定义 HTML 属性

<table autosize="0">

另见 mPDF manual on tables