【问题标题】:Delete pages using fpdf使用 fpdf 删除页面
【发布时间】:2013-06-26 10:24:38
【问题描述】:

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

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

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

【问题讨论】:

  • FPDF 不允许删除页面。您可以尝试使用具有 deletePage(page_no) 功能的 TCPDF 允许您删除页面。
  • 我认为unset($pdf->pages[pageNum]) 应该可以工作,尽管没有经过测试。删除后,您必须重新索引数组以使数组索引适合实际页码。第一页的索引是1。

标签: php pdf fpdf fpdi


【解决方案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 执行的操作,包括确定页面的方向。为了简单起见,我还跳过了一些错误检查。将其视为工作模板,而不是最终代码,因为它最终只是一个快速骨架。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-19
    • 2020-06-25
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多