尝试将图像添加到 pdf 时出现问题

发布于 2024-09-27 19:00:34 字数 294 浏览 0 评论 0原文

我正在使用 java 和 itext 生成 pdf。当我添加我们在以前版本的 pdf 中使用过的图像时,一切都很好。但是当我用新的(它们都是 png-s)替换它时,它会损坏 PDF(我的 PDF 阅读器返回“不是 pdf 或已损坏)。
保存图片时有什么需要特别设置的地方吗?它给我带来了与 jpg 相同的问题。

PS 在生成 pdf 的过程中没有抛出异常。

更新:
我终于成功添加了图像,但这是在减少其颜色数量之后。 我还使用 iText 2.0.6 (由 lowagie.com 提供)

I am generating pdf using java and itext. When I add image that we used before in previous version of the pdf everything is fine. But when I replace it with the new one(they are both png-s) it corrupts the PDF(my PDF reader return "not a pdf or corrupted).
Are there any special things that must be set when saving the image? It gives me the same problem with jpg.

P.S. There are no exceptions thrown during the generation of the pdf.

UPDATE:
I finaly succeeded to add the image, but it was after decreasing the number of its colours.
Also I am using iText 2.0.6 (by lowagie.com)

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

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

发布评论

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

评论(2

仙女 2024-10-04 19:00:34

如果您有 Acrobat 9 Pro(或其试用版),则可以运行 PDF 语法检查。高级 -> 预检...配置文件选项卡,“PDF 分析”,“报告 PDF 语法问题”,然后单击对话框底部的“分析”。

可以分享一下你的PDF吗?我很乐意稍微研究一下。在文本编辑器中打开 PDF 可以获得非常丰富的信息。

我怀疑正在抛出异常,并默默地捕获异常,从而使您的 PDF 处于未定义状态。您的调试器可以将任何抛出的异常转换为断点吗?

另外,您使用的是哪个版本的 iText?

If you have Acrobat 9 Pro (or a trial thereof) you can run the PDF Syntax check. Advanced->Preflight... Profiles tab, "PDF analysis", "Report PDF syntax issues", then click "analyze" at the bottom of the dialog.

Can you share your PDF? I'd be happy to poke at it a bit. Opening a PDF in a text editor can be quite informative.

I suspect that an exception is being thrown, and silently caught, leaving your PDF in an Undefined State. Can your debugger turn any thrown exception into a breakpoint?

Also, what version of iText are you using?

把人绕傻吧 2024-10-04 19:00:34

看来当前的代码有问题。减少图像的颜色数量解决了这个问题。

It looks like there was a problem with the current code. Lowering the number of the colors of the image solved the issue.

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