有没有办法让FPDF/FPDI或Zend_Pdf支持解析大于1.4的PDF?

发布于 2024-07-15 11:09:14 字数 1439 浏览 3 评论 0 原文

我正在尝试使用 FPDI 将现有 PDF(以其他方式创建)添加到使用 FPDF 创建的 PDF 中。 它似乎适用于大多数 PDF,但我收到以下错误:

FPDF error: Unable to find xref table.

经过一些测试,我发现如果我使用 1.4 或更低版本的 PDF 版本(Acrobat v5 或更低版本),它似乎可以工作。 查看该文件似乎是因为 PDF 格式不同。

有解决方法或解决方案吗? 我大概有 10 000 多个用户上传的 PDF,其中一些是新的,一些则不能。 同样令人烦恼的是,FPDI 只是死掉而不是导致某种错误,甚至返回 false

我现在能想到的唯一解决方案是解析 PDF 文件的第一行以确定版本,并仅添加超过版本的版本将工作。

编辑:

我也在 Zend_Pdf 中尝试过这一点,使用 Zend Framework 附带的演示文件得到了以下结果:

Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'Cross-reference streams are not supported yet.' in /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php:331
Stack trace:
#0 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php(455): Zend_Pdf_Parser->_loadXRefTable('116')
#1 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf.php(297): Zend_Pdf_Parser->__construct('/Volumes/Docume...', Object(Zend_Pdf_ElementFactory_Proxy), true)
#2 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf.php(250): Zend_Pdf->__construct('/Volumes/Docume...', NULL, true)
#3 /Volumes/Documents/temp/ZendFramework-1.7.7/demos/Zend/Pdf/demo.php(37): Zend_Pdf::load('/Volumes/Docume...')
#4 {main}
  thrown in /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php on line 331

Is it isn't possible to parse PDFs greater than 1.4?

I am trying to add an existing PDF (created otherwise) to a PDF created with FPDF using FPDI. It seems to work find for most PDFs, but I get the following error:

FPDF error: Unable to find xref table.

After some testing, I figured out that if I use a PDF version of 1.4 or lower (Acrobat v5 or lower) it seems to work. Looking at the file it seems to be because of a different PDF format.

Is there a work around or solution to this? I have probably 10 000+ PDFs uploaded by users, some of the new working, some of them not. It's also annoying that FPDI just dies instead of causing some kind of error or even returning false

The only solution I can think of right now is to parse the first line of the PDF file to determine the version and only add the ones that over versions that will work.

Edit:

I also tried this in Zend_Pdf and it had the following result, using the demo file that comes with the Zend Framework:

Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'Cross-reference streams are not supported yet.' in /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php:331
Stack trace:
#0 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php(455): Zend_Pdf_Parser->_loadXRefTable('116')
#1 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf.php(297): Zend_Pdf_Parser->__construct('/Volumes/Docume...', Object(Zend_Pdf_ElementFactory_Proxy), true)
#2 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf.php(250): Zend_Pdf->__construct('/Volumes/Docume...', NULL, true)
#3 /Volumes/Documents/temp/ZendFramework-1.7.7/demos/Zend/Pdf/demo.php(37): Zend_Pdf::load('/Volumes/Docume...')
#4 {main}
  thrown in /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php on line 331

Is it impossible to parse PDFs greater than 1.4?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

衣神在巴黎 2024-07-22 11:09:14

您可以将 FPDI 与 TCPDF 结合使用,它将生成并读取(使用 FPDI)1.7 版 PDF。

请参阅TCPDF - PDF 的 PHP 类


编辑

我最近遇到了在 FPDI 和 TCPDF 中使用 PDF 的各种版本和格式的问题,我可以确认 1.4 以上的 PDF 版本时好时坏,有趣的是我有很多工作 1.7 PDF,并且在 1.5 和 1.6 上工作大约 50/50。

我通过使用 GhostScript 将所有无法使用的 PDF 文件转换为 v1.4 来解决这个问题,您可以从命令行执行该操作。 使用 GhostScript lib 文件夹中的 ps2pdf14

You can use FPDI with TCPDF, it will generate and read (with FPDI) version 1.7 PDFs.

See TCPDF - PHP class for PDF.


EDIT

I have recently been challenged with the issue of using various versions and formats of PDF with FPDI and TCPDF, and I can confirm that PDF versions above 1.4 are hit and miss, the interesting thing is that I have a lot of working 1.7 PDFs, and works about 50/50 on 1.5 and 1.6.

I worked around the issue by converting all non-workable PDF files to v1.4 using GhostScript which you can exec from the command line. Use ps2pdf14 from the GhostScript lib folder.

°如果伤别离去 2024-07-22 11:09:14

我刚刚发布了两个项目 (TCPDI / tcpdi_parser,分别基于 FPDI 和 tcpdf_parser),与 TCPDF 6(和 FPDF_TPL)一起导入 v1.4 以上的 PDF(到目前为止已测试到 1.6,但一旦我找到 1.7 PFD 来测试它,我将确保它可以与 1.7 一起使用!)而不需要任何商业插件。 基本安装和使用说明可以在 TCPDI README 中找到; 请随意尝试并通过 Github 跟踪器报告任何问题。

I've just released a pair of projects (TCPDI / tcpdi_parser, based on FPDI and tcpdf_parser, respectively) which work with TCPDF 6 (and FPDF_TPL) to import PDFs above v1.4 (tested up to 1.6 so far, but I'll make sure it works with 1.7 once I find a 1.7 PFD to test it with!) without requiring any commercial addons. Basic installation and usage instructions can be found in the TCPDI README; please feel free to try it out and report any issues via the Github tracker.

橘亓 2024-07-22 11:09:14

Setasign 提供 PDF 解析器作为商业插件到 FPDI。 到目前为止,我们使用新的解析器解析 1.7 版本的 PDF 文件时没有遇到任何问题。

Setasign is offering a PDF parser as a commercial addon to FPDI. We had no troubles parsing PDF files up to version 1.7 so far using the new parser.

忆伤 2024-07-22 11:09:14

我发现使用商业版本的 FPDI PDF-Parser 解决了我的问题。 我已经使用它一年了,没有遇到任何它无法解析的 PDF(除非 PDF 已损坏或出现其他奇怪的情况)。

I found that using commerical version of FPDI PDF-Parser solved my problem. I've been using it for a year now and haven't had any PDFs it couln't parse (unless the PDF was corrupt or had something else weird going on).

魔法少女 2024-07-22 11:09:14

对于 symfony,我使用这个库来转换 >1.4
https://packagist.org/packages/xthiago/pdf-version-converter

for symfony, I used this lib to convert >1.4
https://packagist.org/packages/xthiago/pdf-version-converter

も星光 2024-07-22 11:09:14

如果您有 Acrobat PDF writer,则可以操作作业设置以使您正在打印/保存的 PDF 与 PDF 1.4 兼容。 由于我需要这个产品的微小原因,花 100 欧元购买与 1.4 以上版本兼容的商业版本似乎不值得。

If you have Acrobat PDF writer, you can manipulate the job settings to make the PDF you are printing/savingAs to be compatible to PDF 1.4. For the tiny reason I need this product, it doesn't seem worth the 100 euros to get the commercial version that is compatible to versions greater than 1.4.

陈甜 2024-07-22 11:09:14

我的团队删除了部分代码。 我们阻止了代码向 pdf 添加水印。 这为我们解决了问题。 PDF≥1.5

my team had removed some part of the code. we stopped the code from adding watermark to the pdf. this solved the problem for us. PDF >= 1.5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文