2016-08-23 1 views
2

Yiiフレームワーク2を使用して、kartik\mpdf\Pdfクラスを使用して、私のHTMLページをPDF形式でブラウザに返信します。以下は私の設定です。テキストがYiiフレームワーク2のkartik/mpdfで長すぎると、フォントサイズが小さくなります。これを修正する方法は?

$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ページ内に変数があり、長い文字列を返し、そのテキストが小さくなる場合を除いて、すべてが完全に機能します。どうすれば解決できますか?

+0

あなたのHTMLは何ですか?それはテーブルを含んでいますか? – Finwe

+0

はい長い文字列がセルテーブルに存在するため、テーブル全体のフォントサイズが小さくなります。私は代わりにDIVを使用しています。ただ今解決してください。しかし、まだ私がテーブルで作業したい場合に備えて、解決策を探したい。 –

+0

@OConnorと同様の問題がすでにいくつか投稿されており、私はその解決策に答えました。チェックしてください。それは助けるかもしれません - http://stackoverflow.com/questions/26179403/how-to-prevent-table-resizing-in-pdf-using-mpdf-and-php –

答えて

1

mPDFはページに合わせて大きすぎるテーブルのサイズを変更します。これを防ぐため、どちらかあなたのkartik\mpdf\Pdfコンストラクタ呼び出しに

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

を追加したり、またmPDF manual on tablesを参照してくださいカスタムHTML属性

<table autosize="0"> 

を設定します。

関連する問題