php FPDF 错误:此文档 (testcopy.pdf) 可能使用了 FPDI 附带的免费解析器不支持的压缩技术

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12154190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:56:58  来源:igfitidea点击:

FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI

phpfpdffpdi

提问by selva kumar

I am running the following code and giving me this error : FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI.I used another pdf named test.pdfand that works fine but it is giving me error in testcopy.pdf.

我正在运行以下代码并给我这个错误:FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI.我使用了另一个名为 pdftest.pdf并且工作正常但它给了我错误testcopy.pdf.

I think this is parser problem. Anyone know any other parser that can be used with fpdf to avoid this error?

我认为这是解析器问题。任何人都知道可以与 fpdf 一起使用以避免此错误的任何其他解析器?

My code:

我的代码:

require('fpdf17/fpdf.php'); 
require('fpdf17/fpdi.php'); 
// initiate FPDI 
$pdf = new FPDI(); 
while (ob_get_level())
ob_end_clean();
header("Content-Encoding: None", true);
// set the sourcefile 
$pagecount = $pdf->setSourceFile('testcopy.pdf');

I want to split pdf in two pdfs and want to attach both pdfs in file attachments field.How to save pdf to server. Can it be possible with fpdf?

我想将 pdf 分成两个 pdf,并希望在文件附件字段中附加两个 pdf。如何将 pdf 保存到服务器。fpdf可以吗?

回答by selva kumar

Yes, Exactly the FPDF library supports only PDF version 1.4 & lesser. So to over come from this issue use GhostScript. This script helps to change the PDF versions dynamically.

是的,FPDF 库仅支持 PDF 1.4 及更低版本。所以要解决这个问题,请使用GhostScript。此脚本有助于动态更改 PDF 版本。

(1) Download the Ghostscripthere.

(1) 在此处下载Ghostscript

(2) Install the Ghostscript and define the environment variable PATH.

(2)安装Ghostscript并定义环境变量PATH。

(3) Then, use the below php code to change the PDF version.

(3) 然后,使用下面的 php 代码更改 PDF 版本。

shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf.""); 

(4) Now we get PDF with version 1.4 as output, then continue with FPDF.

(4) 现在我们得到 1.4 版的 PDF 作为输出,然后继续 FPDF。

Enjoy!

享受!

回答by shalamos

The file needs to be PDF 1.4 (Acrobat 5) or lower. If you have Adobe Acrobat Pro you can change this with Document->Decrease File Size.

该文件需要为 PDF 1.4 (Acrobat 5) 或更低版本。如果您有 Adob​​e Acrobat Pro,您可以使用 Document->Decrease File Size 更改此设置。

回答by John

I had the same issue that PDFMerger does not work with certain PDF. It seems that Adobe keep updating compression way of pdf extension.

我遇到了同样的问题,即 PDFMerger 不适用于某些 PDF。Adobe 似乎一直在更新 pdf 扩展的压缩方式。

I found solution with Chrome.

我找到了 Chrome 的解决方案。

1. Open the PDF file(which does not work with PDFMerger) with Chrome
2. Right Click and Print
3. Change destination as [Save as PDF]
4. This exported PDF file is compatible with PDFMerger

回答by Mark N Hopgood

Looking through the answers so far, I wasn't able to resolve the issue. Here's why and you may have the same issue so this answer would be invaluable to you too.

到目前为止,我无法解决问题。这就是原因,您可能会遇到同样的问题,因此这个答案对您来说也是无价之宝。

I did not have access to acrobat, so I couldn't downgrade the version of the original PDF. I wasn't in a position to purchase the newer version of the library which has upgraded encryption.

我无法访问 acrobat,因此无法降级原始 PDF 的版本。我无法购买已升级加密的库的较新版本。

In the end I used an online PDF converter to downgrade to version 5 (1.4)

最后我使用在线PDF转换器降级到版本5(1.4)

If you are not able to find one, here's a link for completeness.

如果您找不到,这里有一个完整的链接。

https://docupub.com/pdfconvert/

(bear in mind that the contents of a link may change)

(请记住,链接的内容可能会更改)

回答by Anton Mitsev

Here is my answer from another topic:

这是我从另一个主题的回答:

"It can be overcome by re-saving the template and change compression type. In Adobe Acrobat Pro go to File->Save As->Optimised PDF-> Popup left list - Clean Up, Object Compression Options -> Change to "Compress document structure" -> OK to save"

“它可以通过重新保存模板和更改压缩类型来克服。在 Adob​​e Acrobat Pro 中,转到文件->另存为->优化的 PDF-> 弹出左列表 - 清理、对象压缩选项 -> 更改为“压缩文档”结构”->确定保存”

Ref. Editing password protected pdfs with fpdi

参考 使用 fpdi 编辑受密码保护的 pdf

回答by Michael Nass

For those that don't have any of the pro versions of Acrobat:

对于那些没有任何专业版 Acrobat 的人:

I was having this problem with new versions of Word when trying to use the Office functionality to save to a PDF. It seems the PDF conversion tool supplied in Office is using the newer formats. Here's how I fixed it.

在尝试使用 Office 功能保存为 PDF 时,我在使用新版本的 Word 时遇到了这个问题。Office 中提供的 PDF 转换工具似乎正在使用较新的格式。这是我修复它的方法。

  • Install NitroPDF free version (May work with another free PDF creator that can be downloaded)
  • Go to the Word document and select 'Print'.
  • In the print options, instead of your printer, select 'Nitro PDF Creator (Reader 3)' or whatever the current version is.
  • A dialog box will open and allow you to select where to save the PDF.
  • 安装 NitroPDF 免费版(可以与另一个可以下载的免费 PDF 创建者一起使用)
  • 转到 Word 文档并选择“打印”。
  • 在打印选项中,而不是您的打印机,选择“Nitro PDF Creator (Reader 3)”或任何当前版本。
  • 将打开一个对话框,让您选择保存 PDF 的位置。

The version saved was able to be opened by FPDF.

保存的版本可以被 FPDF 打开。

Hope it helps

希望能帮助到你

回答by rekire

I had a very similar error like you. My solution was to convert the pdf to a lower pdf version. Than everything worked like expected.

我有和你一样的错误。我的解决方案是将 pdf 转换为较低的 pdf 版本。比一切都像预期的那样工作。

I hope that simple trick will help you!

我希望这个简单的技巧能帮到你!