是什么原因导致“图像数据不足”?在 PDF 中

发布于 2024-09-26 01:09:11 字数 298 浏览 0 评论 0原文

我有一个 Python 程序(使用 pyPDF),可以合并一堆不同的 PDF 文档。有时,生成的 pdf 很好,除了中间有一些空白页。当我使用 Acrobat Reader 查看这些文档时,收到一条错误消息:“图像数据不足”。当我使用 FoxIT Reader 查看文档时,我看到一些空白页和模糊的图像。

创建空白页面的 PDF 的唯一奇怪之处在于它似乎是 PDF 版本 1.4,而 PyPdf 似乎使用 PDF 版本 1.3 创建文件。

1)版本问题听起来像是我的问题的根本原因吗?

2)有没有办法让PyPdf正确处理这个问题?

I have a program in Python (using pyPDF) that merges a bunch of different PDF documents. Sometimes, the resulting pdf is fine, except for some blank pages in the middle. When I view these documents with Acrobat Reader, I get an error message saying "insufficient data for image". When I view the documents with FoxIT Reader, I get some blank pages and a munged image.

The only odd thing about the PDF that creates the blank pages is that it seems to be PDF Version 1.4, and PyPdf seems to create files with PDF Version 1.3.

1) Does the version thing sound like the root cause of my problem?

2) Is there a way to get PyPdf to handle this correctly?

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

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

发布评论

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

评论(3

晒暮凉 2024-10-03 01:09:11

这可能与 Windows 有关,而不是与 .pdf 文件有关。

http://support.microsoft.com/kb/2506795

祝你好运!

This might be related to Windows not actually the .pdf file.

http://support.microsoft.com/kb/2506795

Good luck!

北方的巷 2024-10-03 01:09:11

我遇到了这个问题,并且能够通过在十六进制编辑器中并排查看原始 pdf 和 PyPDF 来解决这个问题。

问题似乎是 PyPDF 实际上遗漏了一个字节 - 看起来每个图像流中的第一个字节可能丢失了。当我将字节添加到 PyPDF 文件时,pdf 可以正常打开,没有错误。

I had this problem, and was able to figure it out by looking at the original pdf side by side with the PyPDF one in a hex editor.

The problem seems to be that PyPDF actually leaves off a byte - it looks like probably the first byte in each image stream is missing. When I added the bytes to the PyPDF file, the pdf opened up fine without the error.

不寐倦长更 2024-10-03 01:09:11

我怀疑图像 XObject 流格式错误。如果无法访问包含问题的 PDF,大多数人只能猜测。

例如,如果 pdf 信息显示图像宽 10 像素、高 10 像素、每像素 8 位,则流应解压缩为 100 字节。如果它解压缩到小于这个值,我预计会出现像您所看到的错误。

对于您碰巧使用的任何图像格式,这可能是 pypdf 中的一个错误。

IIRC,PDF 中没有扫描线填充,也不关心字边界,但如果需要,最后一位会被填充为一个字节。那里的混乱很容易导致字节过多,但这不是这里的问题。

它也可能是一个糟糕的色彩空间。如果您有一个索引彩色图像 (gif),并且他们将其转换为 RGB 图像的一半,但使用原始索引颜色字节,您将获得一个可能期望每个像素 n*3 位的流,但仅每个像素有 n 位。

这可能是一个较旧的错误,已在 pypdf 中修复。您使用的是当前版本吗?

I suspect that the image XObject stream is Malformed. Without access to a PDF with the problem, all most folks can do is guess.

For example, if the pdf info says the image is 10 pixels wide, 10 pixels high, and 8 bits per pixel, then the stream should uncompress to 100 bytes. If it uncompressed to less than that, I'd expect an error like the one you're seeing.

The is probably a bug in pypdf regarding whatever image format you happen to be using.

IIRC, there's is no scan-line padding in PDF and no concern for word boundaries, though the last bits are padded out to a byte if need be. Confusion there could easily lead to too many bytes, which isn't the problem here.

It could also be a bad color space. If you've got an indexed color image (gif), and they translate it half way to an RGB image, but use the original indexed color bytes, you'd get a stream that might expect n*3 bits per pixel, but only have n bits per pixel.

It's possible that this is an older bug that's been fixed in pypdf. Are you using the current version?

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