使用 PHP(或可能是 perl)将 PDF 文档拆分为单独的页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2584133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Split PDF documents into separate pages using PHP (or possibly perl)
提问by Simon Stevens
Can anybody point me towards a PHP library or script that would allow me to split a pdf consisting of multiple pages into separate files, each containing 1 page. The PDFLib documentation doesn't appear to allow this and Google hasn't been particularly helpful.
任何人都可以向我指出一个 PHP 库或脚本,它允许我将包含多个页面的 pdf 拆分为单独的文件,每个文件包含 1 页。PDFLib 文档似乎不允许这样做,谷歌也没有特别有帮助。
I could possibly also use Perl, but it would be very inconvenient to do so.
我也可以使用 Perl,但这样做会很不方便。
回答by Sinan ünür
I have used PDF::Reuse. It makes it so easy it is not even funny. Here is the relevant snippet from one of my scripts:
我使用过PDF::Reuse。它使它变得如此简单,甚至都不好笑。这是我的一个脚本中的相关片段:
while ( my $line = <$page_list> ) {
chomp $line;
my ($class, $drug, $page) = split ' ', $line;
my $dir = canonpath( catfile $OUTPUT_DIR, $class );
mkdir $dir unless -e $dir;
my $target = canonpath( catfile $dir, "$drug.pdf" );
prFile( $target );
prCompress( 1 );
prDoc( $INPUT_PDF, $page, $page + 1 );
prEnd();
}
回答by runrig
回答by Alexandr Ciornii
回答by FlowPaper Team
I would vote for using PDFTk even if you choose to call it PDFTk from PHP. It has excellent track record of how to do this. The following example shows how to split your PDF with PDFTk
即使您选择从 PHP 调用 PDFTk,我也会投票支持使用 PDFTk。它在如何做到这一点方面有着出色的记录。以下示例显示了如何使用 PDFTk 拆分您的 PDF
pdf2json.exe Paper.pdf -enc UTF-8 -compress -split 10 Paper.pdf_%.js
(example taken from this url)
(示例取自此 url)

