Split PDF into chunks by page range in Php

爱⌒轻易说出口 提交于 2021-02-05 09:40:59

问题


so after browsing through many packages like TCPDF, FPDP, DOM2PDF and many other excellent php pdf packages, I couldn't find this feature in any packages where it allows to split the pdf file by page range. for example I want to split the pdf from page 20-100 or 30-50. or create a pdf from a pdf ranging from page 20-100. so is there any library that has this feature ?


回答1:


PDFMerger has this functionality, and I personally enjoy its simplicity.

$pdf = new PDFMerger;
$pdf->addPDF('pdf1.pdf','20-100');
$pdf->addPDF('pdf2.pdf','30-50');
$pdf->merge(); // output PDF, you can specify additional parameters here



回答2:


You can do this with the combination of FPDI and FPDF.

$new_pdf = new setasign\Fpdi\FPDI();
        
for($i = 20; $i <= 200; $i++){
    $new_pdf->AddPage();
    $new_pdf->setSourceFile("source.pdf");
    $new_pdf->useTemplate($new_pdf->importPage($i));
}

$new_pdf->Output("output.pdf", "F");


来源:https://stackoverflow.com/questions/29609647/split-pdf-into-chunks-by-page-range-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!