PDFMerger.php的问题

PDFMerger.php的问题,php,merge,Php,Merge,我想合并2个或多个PDF,但符合条件。我正在使用PDFMerger.php()。我发现的代码是: <?php include 'PDFMerger.php'; $pdf = new PDFMerger; $pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4') ->addPDF('samplepdfs/two.pdf', '1-2') ->addPDF('samplepdfs/three.pd

我想合并2个或多个PDF,但符合条件。我正在使用PDFMerger.php()。我发现的代码是:

<?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');
?>

这个代码对我来说很好用。但我这里有个问题。我不知道我的PDF中的页数,因为它们是动态生成的。那么,如果我想从三个.pdf文件中跳过第一页或最后一页(假设有5页)怎么办&我没有页面计数

所以输出应该是1.pdf的所有页面+2.pdf的所有页面+3.pdf的2-5页


提前感谢。

尝试使用以下代码查找PDF中的数字页:

exec('/usr/bin/pdfinfo '.$tmpfname.' | awk \'/Pages/ {print $2}\'', $output); 

函数getNumPagesInPDF($file) { 如果(!file_存在($file)),则返回null; if(!$fp=@fopen($file,“r”))返回null; $max=0; 而(!feof($fp)){ $line=fgets($fp,255); if(预匹配('/\/Count[0-9]+/',$line,$matches)){ 预匹配('/[0-9]+/',$matches[0],$matches2);
如果没有得到任何东西。我的文件在'samplepdfs/one.pdf'中。请告诉我如何将此代码添加到我的程序中。谢谢。现在我得到了页数。但是之后呢?请查看上面的代码并告诉我
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;

}