gpt4 book ai didi

java - PDF-A 文件验证

转载 作者:行者123 更新时间:2023-11-30 06:50:40 24 4
gpt4 key购买 nike

我正在尝试使用 PdfBox 实现 java pdf-a validator 。我正在处理的文件是数字签名的 pdf (PADES)。我使用 pdfbox 或在线工具,结果是:

        PreflightDocument document = parser.getPreflightDocument();
document.validate();

1.1 : Header Syntax error, First line must match %PDF-1.\d
1.1 : Header Syntax error, Second line must begin with '%' followed by at least 4 bytes greater than 127
1.0 : Syntax error, Missing end of file marker '%%EOF'

但是当我用任何阅读器打开该文件时,它的格式确实是 pdf-a。查看 pdf 内部,实际上第一行不是 %PDF-1,也不是最后 %%EOF。可能是因为pdf已签名。可能是吗?万一我如何在签名的 pdf 中克服这种验证?

0ƒ;f    *†H†÷
 ƒ;V0ƒ;Q10
`†He
 ƒ;‡=ƒ;‡8%PDF-1.4
%ÿÿÿÿ
1 0 obj
<<
...
....
.....

注意第四行末尾的“%PDF-1.4”

最佳答案

稍微充实一下 Tilman 的评论...

标题

根据 PDF 规范 ISO 32000-1:

7.5.2 File Header

The first line of a PDF file shall be a header consisting of the 5 characters %PDF– followed by a version number of the form 1.N, where N is a digit between 0 and 7.

正如“应”所示,这是一项要求。因此,您的文件不仅不是有效的 PDF/A 文档,甚至不是有效的 PDF。

如果您想知道为什么 Adob​​e Reader 不提示...Adobe 在附件 H.3 实现说明中的 PDF 1.7 引用中指出,他们的软件对 PDF header 要求的处理相当宽松:

  1. Acrobat viewers require only that the header appear somewhere within the first 1024 bytes of the file.

因此,您拥有一个无效的 PDF,但 Adob​​e 查看器仍会显示该 PDF。

页脚

再次根据PDF规范

7.5.5 File Trailer

The trailer of a PDF file enables a conforming reader to quickly find the cross-reference table and certain special objects. Conforming readers should read a PDF file from its end. The last line of the file shall contain only the end-of-file marker, %%EOF.

Adobe 查看器再次接受一些不符合此要求的文件;根据 Adob​​e PDF 引用:

  1. Acrobat viewers require only that the %%EOF marker appear somewhere within the last 1024 bytes of the file.

由于文件的最后一行不是 %%EOF,这是它无法满足的有效 PDF 文件的另一个要求...

<小时/>

关于您的主张:

But when I open the file with any reader it's format is indeed pdf-a

Adobe Reader 不会检查文件是否确实有效的 PDF/A,它仅报告文件声称的内容

关于java - PDF-A 文件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42856677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com