使用 TCPDF 将现有 PDF 与动态生成的 PDF 合并 [英] Merge existing PDF with dynamically generated PDF using TCPDF

查看:95
本文介绍了使用 TCPDF 将现有 PDF 与动态生成的 PDF 合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TCPDF 生成 PDF 文档.我的要求是在动态生成的 PDF 的最后一页合并现有的 PDF 内容.

I am generating a PDF document using TCPDF. My requirement is to merge an existing PDF content at the last page of the dynamically generated PDF.

推荐答案

到目前为止,解决您问题的最佳方法是使用 FPDI.

By far the best solution to your problem is to use FPDI.

https://github.com/Setasign/FPDI

它的工作方式是 FPDI 扩展了 TCPPDF,因此您可以使用您使用的所有方法来处理 FPDI 对象习惯于与 TCPD 一起使用,但需要使用其他方法从现有 PDF 文件导入页面(setSourceFilegetTemplateSize使用模板).

The way it works is that FPDI extends TCPDF so you can work with an FPDI object using all of the methods that you're used to using with TCPDF, but with the additional methods that you need to import pages from existing PDF files (setSourceFile, getTemplateSize and useTemplate).

设置起来有点令人生畏,但如果您使用 Composer,它实际上非常容易.只需将 setasign/fpdisetasign/fpdi-tcpdf 添加到您的 composer.json 文件中,然后使用 FPDI 代替您的 TCPPDF 实例.我发现我什至不必像 github 页面上提到的那样调用 class_exists('TCPPDF', true) .一旦我将这些其他条目添加到 composer.json 并运行 composer dumpautoload 它就可以工作了.

It looks a bit daunting to set up, but if you're using Composer it is actually incredibly easy. Just add setasign/fpdi and setasign/fpdi-tcpdf to your composer.json file and then use an instance of FPDI in place of your TCPDF instance. I found I didn't even have to call class_exists('TCPDF', true) as mentioned on the github page. Once I added those other entries to composer.json and ran composer dumpautoload it just worked.

这篇关于使用 TCPDF 将现有 PDF 与动态生成的 PDF 合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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