用 PHP 合并 PDF 文件 [英] Merge PDF files with PHP

查看:52
本文介绍了用 PHP 合并 PDF 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的概念是 - 网站中有 10 个 pdf 文件.用户可以选择一些 pdf 文件,然后选择合并以创建包含所选页面的单个 pdf 文件.我怎样才能用 php 做到这一点?

My concept is - there are 10 pdf files in a website. User can select some pdf files and then select merge to create a single pdf file which contains the selected pages. How can i do this with php?

推荐答案

我以前做过这个.我有一个用 fpdf 生成的 pdf,我需要向其中添加可变数量的 PDF.

I've done this before. I had a pdf that I generated with fpdf, and I needed to add on a variable amount of PDFs to it.

所以我已经有一个 fpdf 对象和页面设置(http://www.fpdf.org/)我使用 fpdi 导入文件(http://www.setasign.de/products/pdf-php-solutions/fpdi/)通过扩展PDF类添加FDPI:

So I already had an fpdf object and page set up (http://www.fpdf.org/) And I used fpdi to import the files (http://www.setasign.de/products/pdf-php-solutions/fpdi/) FDPI is added by extending the PDF class:

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.它非常适合我需要的用途.

This basically makes each pdf into an image to put into your other pdf. It worked amazingly well for what I needed it for.

这篇关于用 PHP 合并 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆