我有太多的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');
感谢您的帮助。
答案 0 :(得分:0)
您可以使用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);