Yii2 mPdf Kartik: Set Height and Width Paper

ⅰ亾dé卋堺 提交于 2019-12-11 04:16:15

问题


How to set custom height and width on PDF format like this:

I want set height: 13.6cm and width: 21.2cm

if I export to PDF, paper size is always in A4 format, how to make paper size to be 13.6cm (height) and **21.2cm (width) as in the picture above

I use mpdf kartik on yii2 ..

this my controller code:

$pdf = new Pdf([
                'mode' => Pdf::MODE_UTF8,
                'format' => Pdf::FORMAT_A4,
                'destination' => Pdf::DEST_BROWSER,
                'content' => $content,
                'cssFile' => \Yii::getAlias('@webroot') .'/css/pdf/pdf-pfi.css',
                'marginLeft' => 5, 'marginTop' => 5, 'marginRight' => 5, 'marginBottom' => 5,
                'defaultFont' => 'Calibri',
            ]);
            return $pdf->render();

hopefully it can be helped ...


回答1:


The format can be specified either as a pre-defined page size, or as an array of width and height in millimetres.

Use like

$pdf = new Pdf([
    'mode' => Pdf::MODE_UTF8,
    'format' => [212, 136], // here define custom [width, height] in mm
    // 'format' => Pdf::FORMAT_A4,
    'destination' => Pdf::DEST_BROWSER,
    'content' => $content,
    'cssFile' => \Yii::getAlias('@webroot') .'/css/pdf/pdf-pfi.css',
    'marginLeft' => 5, 
    'marginTop' => 5, 
    'marginRight' => 5, 
    'marginBottom' => 5,
    'defaultFont' => 'Calibri',
]);
return $pdf->render();

Refer kartik-v/yii2-mpdf or mPdf



来源:https://stackoverflow.com/questions/53699037/yii2-mpdf-kartik-set-height-and-width-paper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!