【问题标题】:combine pdf files together for {pdf ver 1.7}将 pdf 文件组合在一起用于 {pdf ver 1.7}
【发布时间】:2016-05-01 13:49:32
【问题描述】:

我的 pdf 文件太多,我无法更改 pdf 版本或购买 FPDI 插件。 有没有办法免费将 pdf 文件合并在一起? 我用这个:

<?php
require_once('fpdf.php');
require_once('fpdi.php');

class ConcatPdf extends FPDI
{
    public $files = array();

    public function setFiles($files)
    {
        $this->files = $files;
    }

    public function concat()
    {
        foreach($this->files AS $file) {
            $pageCount = $this->setSourceFile($file);
            for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
                 $tplIdx = $this->ImportPage($pageNo);
                 $s = $this->getTemplatesize($tplIdx);
                 $this->AddPage($s['w'] > $s['h'] ? 'L' : 'P', array($s['w'], $s['h']));
                 $this->useTemplate($tplIdx);
            }
        }
    }
}

$pdf = new ConcatPdf();
$pdf->setFiles(array("Boombastic-Box.pdf", "Fantastic-Speaker.pdf", "Noisy-Tube.pdf"));
$pdf->concat();

$pdf->Output('concat.pdf', 'I');

感谢您的帮助。

【问题讨论】:

    标签: php pdf merge


    【解决方案1】:

    您可以使用 PDFMerger 脚本 你可以找到它PDF Merger

    你也可以使用下面的代码

    $fileArray= array("name1.pdf","name2.pdf","name3.pdf","name4.pdf");
    
    $datadir = "save_path/";
    $outputName = $datadir."merged.pdf";
    
    $cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName ";
    //Add each pdf file to the end of the command
    foreach($fileArray as $file) {
        $cmd .= $file." ";
    }
    $result = shell_exec($cmd);
    

    【讨论】:

    • 你确定吗?这适用于 pdf 1.7 版吗?我以前试过。
    • FPDF 错误:本文档 (test.pdf) 可能使用了 FPDI 附带的免费解析器不支持的压缩技术。
    • 结束这个问题使用Ghost Script。此脚本有助于动态更改 PDF 版本。 (1) 在此处下载 Ghostscript。 (2) 安装Ghostscript并定义环境变量PATH。 (3) 然后,使用以下 php 代码更改 PDF 版本。 shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf.""); (4) 现在我们得到 1.4 版的 PDF 作为输出,然后继续 FPDF。享受吧!
    • 是的,使用 PHP 我的代码 &lt;?php include 'PDFMerger.php'; $pdf = new PDFMerger; $pdf-&gt;addPDF('1.pdf', 'all') -&gt;addPDF('2.pdf', 'all') -&gt;addPDF('7.pdf', 'all') -&gt;merge('file', 'TEST2.pdf');
    猜你喜欢
    • 1970-01-01
    • 2012-09-17
    • 2015-03-27
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多