我的概念是-在一个网站中有10个pdf文件。用户可以选择一些pdf文件,然后选择合并来创建包含所选页面的单个pdf文件。我怎么用php做到这一点呢?
发布于 2011-01-25 23:40:38
我以前也这么做过。我有一个我用fpdf生成的pdf,我需要在它上面添加不同数量的pdf。
所以我已经有了一个fpdf对象和页面设置(http://www.fpdf.org/),我使用fpdi来导入文件(http://www.setasign.de/products/pdf-php-solutions/fpdi/),fpdi是通过扩展PDF类添加的:
class PDF extends FPDI
{
}
$pdffile = "Filename.pdf";
$pagecount = $pdf->setSourceFile($pdffile);
for($i=0; $i<$pagecount; $i++){
$pdf->AddPage();
$tplidx = $pdf->importPage($i+1, '/MediaBox');
$pdf->useTemplate($tplidx, 10, 10, 200);
}
这基本上使每个pdf成为一个图像,以放入您的另一个pdf。在我需要它的地方,它工作得非常好。
发布于 2011-06-09 12:45:10
下面是php PDF merge命令。
$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);
我忘记了我找到它的地方的链接,但它工作得很好。
注意:您应该安装gs (在linux上,也可能在Mac上)或Ghostscript (在windows上)才能正常工作。
发布于 2014-04-25 04:54:12
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=".$new." ".implode(" ", $files);
shell_exec($cmd);
Chauhan答案的简化版本
https://stackoverflow.com/questions/4794435
复制相似问题