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

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

问题描述

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

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天全站免登陆