我有许多页面大小不同的 PDF 文件,所以当我使用默认页面大小 (A4) 的 setSourceFile > importPage > useTemplate 时。某些文件的页面尺寸大于 A4 的内容会出现页面溢出。
$mpdf = new \Mpdf\Mpdf();
$arrPage = array(
'orientation' => 'P',
'mgl' => '0',
'mgr' => '0',
'mgt' => '0',
'mgb' => '0',
'mgh' => '0',
'mgf' => '0',
'newformat' => array(210,297)
);
$pagecount = $mpdf->setSourceFile($_GET['docFile']);
for ($i = 1; $i <= $pagecount; $i++) {
$mpdf->AddPageByArray($arrPage);
$tplId = $mpdf->importPage($i);
$mpdf->useTemplate($tplId);
}
$mpdf->Output();
如何从导入文件中获取页面大小,以便在导入文件之前匹配页面大小。还有页面方向。
试试这个:
/* ... */
$tplId = $mpdf->importPage($i);
$arrSize = $mpdf->getTemplateSize($tplId);
/* ... */