Yii2 mPdf Kartik:设置高度和宽度纸张 [英] Yii2 mPdf Kartik: Set Height and Width Paper

查看:442
本文介绍了Yii2 mPdf Kartik:设置高度和宽度纸张的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在这样的PDF格式上设置自定义高度宽度:

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

我想要设置高度:13.6厘米,宽度:21.2厘米

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

如果我导出为PDF,则纸张尺寸始终为 A4格式, 如何使纸张尺寸变为上图所示的 13.6cm(高度)和** 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

我在yii2上使用mpdf kartik..

I use mpdf kartik on yii2 ..

这是我的控制器代码:

$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 ...

推荐答案

可以将格式指定为预定义的页面大小,也可以指定为以毫米为单位的宽度和高度的数组.

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

使用方式

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

引用 kartik-v/yii2-mpdf 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆