0

我想从使用 fpdf 库创建的 PDF 中删除一些页面,

$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage(); 

是否有任何功能可以删除页面。我不熟悉 FPDF。

4

1 回答 1

1

您想使用FPDI。摆脱“删除”页面的心态。相反,将其视为“不插入”页面。假设我想跳过第 3、15、17 和 22 页。您可以这样做:

$pdf = new FPDI();
$pageCount = $pdf->setSourceFile('document.pdf');

//  Array of pages to skip -- modify this to fit your needs
$skipPages = [3,15,17,22];

//  Add all pages of source to new document
for( $pageNo=1; $pageNo<=$pageCount; $pageNo++ )
{
    //  Skip undesired pages
    if( in_array($pageNo,$skipPages) )
        continue;

    //  Add page to the document
    $templateID = $pdf->importPage($pageNo);
    $pdf->getTemplateSize($templateID);
    $pdf->addPage();
    $pdf->useTemplate($templateID);
}

$pdf->Output();

请注意,我没有包括很多你可以用 FPDI 做的事情,包括确定页面的方向。为了简单起见,我还跳过了一些错误检查。将其视为可以使用的模板,而不是最终代码,因为它最终只是一个快速骨架。

于 2015-05-14T16:08:53.610 回答