如何使用 mPDF 从导入 PDF 文件中获取页面大小

问题描述 投票:0回答:1

我有许多页面大小不同的 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();

如何从导入文件中获取页面大小,以便在导入文件之前匹配页面大小。还有页面方向。

php mpdf
1个回答
0
投票

试试这个:

/* ... */
$tplId = $mpdf->importPage($i);
$arrSize = $mpdf->getTemplateSize($tplId);
/* ... */
© www.soinside.com 2019 - 2024. All rights reserved.