如何发现以编程方式生成的 PDF 中的问题?

发布于 2024-09-17 12:27:12 字数 1539 浏览 1 评论 0原文

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

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

发布评论

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

评论(2

与往事干杯 2024-09-24 12:27:12

“最便宜”(同时相当可靠!)的方法是使用 Ghostscript。让 Ghostscript 解释 PDF 并查看它给出的返回值。如果没有问题,则 PDF 文件应该没问题。在 Windows 上:

 gswin32c.exe ^
       -o nul
       -sDEVICE=nullpage ^
        d:/path/to/file.pdf

nullpage 输出设备不会创建任何新文件。但如果 Ghostscript 遇到错误,它会在 stdout/stderr 上报告。检查 %errorlevel% 伪环境变量的内容。 -- 在 Linux 上:(

 gs \
       -o /dev/null \
       -sDEVICE=nullpage \
        /path/to/file.pdf

使用 echo $? 检查返回值是否为 0 值,表示“没有问题”。)

如果出现错误,Ghostscript 会发出一些信息,这些信息可能是对你有帮助。无论如何,至少您可以肯定地识别出那些没有问题的文件:如果 Ghostscript 可以处理它们,Acrobat (Reader) 渲染它们也不会出现问题。

The "cheapest" (and at the same time quite reliable!) way is to use Ghostscript. Let Ghostscript interpret the PDF and see which return value it gives. If it has no problem, the PDF file should be OK. On Windows:

 gswin32c.exe ^
       -o nul
       -sDEVICE=nullpage ^
        d:/path/to/file.pdf

The nullpage output device will not create any new file. But Ghostscript will tell on stdout/stderr if it encounters an error. Check for the content of the %errorlevel% pseudo environment variable. -- On Linux:

 gs \
       -o /dev/null \
       -sDEVICE=nullpage \
        /path/to/file.pdf

(Check return value with echo $? for a 0 value for "no problems".)

In case of errors, Ghostscript issues some info which may be helpful to you. In any case, at least you can positively identify those files which do have NO problems: if Ghostscript can process them, Acrobat (Reader) will have no problem rendering them too.

花开柳相依 2024-09-24 12:27:12

验证 PDF 文件可能是一项相当棘手的任务——主要是因为正确完成验证所需的工具非常昂贵。

Acrobat 有一个工具(“高级”>“预检”>“PDF 分析”>“报告 PDF 语法问题”)可让您扫描 PDF 中是否存在任何语法问题,但无法以编程方式访问该工具。

Appligent 有一个名为 pdfHarmmony 的工具,该工具由 Adob​​e 的 PDF 库提供支持,可以通过编程方式访问,但它非常昂贵(2500美元以上)。如果您负担得起,此选项将为您带来最佳结果。

还有另一个选项是 3-Heights PDF Analysis &修复,不知道质量如何,不过同样贵。

SourceForge 上的这个PDF Validator 工具可能会让您感兴趣,但是,它仅分析文档结构而不是内容本身,因此不会拾取损坏的图像或内容流。

不幸的是,由于详细分析 PDF 文件很困难,实际上没有任何免费工具可以正确完成此任务,但我认为检查文档结构的工具总比没有好。

Validating PDF files can be quite a tricky task -- primarily because the tools required to do it properly are very expensive.

Acrobat has a tool (Advanced > Preflight > PDF Analysis > Report PDF syntax issues) that lets you scan a PDF for any syntax issues, but that tool can't be accessed programmatically.

Appligent has a tool called pdfHarmmony, which is powered by Adobe's PDF Library, and can be accessed programmatically, but it is very expensive (US$2500+). This option would give you the best results if you can afford it.

There's another option which is 3-Heights PDF Analysis & Repair, I don't know what it's quality is like, but it is similarly expensive.

This PDF Validator tool on SourceForge might interest you, however, it only analyzes the documents structure and not the content itself, so corrupt images or content streams won't be picked up.

Unfortunately, due to the difficulty of analyzing PDF files in detail, there aren't really any free tools that can do it properly, but I suppose a tool that checks the documents structure is better than nothing.

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