Yii2 mPdf Kartik: Set Height and Width Paper

2019-07-30 00:05发布

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

enter image description here

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条回答
冷血范
2楼-- · 2019-07-30 00:53

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

查看更多
登录 后发表回答