我希望合并2个或更多pdfs,但与条件。我正在使用PDFMerger.php (http://pdfmerger.codeplex.com/)。我发现的密码是:
<?php
include 'PDFMerger.php';
$pdf = new PDFMerger;
$pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4')
->addPDF('samplepdfs/two.pdf', '1-2')
->addPDF('samplepdfs/three.pdf', 'all')
->merge('download', 'samplepdfs/TEST2.pdf');
?>这段代码对我来说很好。但我在这里有个问题。我不知道pdfs中的页面计数,因为它们是动态生成的。因此,如果我想跳过three.pdf中的第一页或最后一页(假设有5页)-我没有页面计数。
所以输出应该是所有的one.pdf+all页面,即two.pdf+2-5页的three.pdf
提前谢谢。
发布于 2014-07-02 08:25:10
尝试使用以下代码查找PDF中的数字页:
exec('/usr/bin/pdfinfo '.$tmpfname.' | awk \'/Pages/ {print $2}\'', $output); 或
function getNumPagesInPDF($file)
{
if(!file_exists($file))return null;
if (!$fp = @fopen($file,"r"))return null;
$max=0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)){
preg_match('/[0-9]+/',$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
}
}
fclose($fp);
return (int)$max;
}https://stackoverflow.com/questions/24525955
复制相似问题