[reportlab-users] Corrupt PDF when including image
Michael Johnson
mjjohnson.geo at yahoo.com
Thu Feb 9 15:29:18 EST 2012
I just started using reportlab (2.5) for a project I'm working on, and the PDFs that I'm generating can't be opened by either Ghostscript 9.04 or Acrobat 9. However, they open fine in Okular and in Gmail's PDF preview. I did some searching and found that for PDFs that include images, sometimes a particular image will cause problems. However, I tried switching to a completely different image and had no better luck. Here's a minimum working Python example:
#!/usr/bin/env python
from reportlab.lib.units import inch
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas
bg = "test_image.png"
c = canvas.Canvas('test.pdf', 'letter')
image = ImageReader(bg)
c.drawImage(image, .25*inch, .25*inch, width=8*inch, height=10.5*inch)
c.showPage()
c.save()
####################
If I open the output of test.pdf after running the above Python, Acrobat returns an error stating "There was a problem reading this document (14)", while with Ghostscript, when I run the following command:
`gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test_small.pdf -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 test.pdf`
I get the following error message:
**** Error reading a content stream. The page may be incomplete.
Error: /typecheck in --run--
Operand stack:
--dict:3/3(L)-- 44033 4 0 --nostringval-- Contents --nostringval-- MediaBox --nostringval-- 0 0 5 (l) --nostringval-- --dict:12/12(ro)(G)--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1894 1 3 %oparray_pop 1893 1 3 %oparray_pop 1877 1 3 %oparray_pop --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval--
Dictionary stack:
--dict:1159/1684(ro)(G)-- --dict:1/20(G)-- --dict:82/200(L)-- --dict:82/200(L)-- --dict:108/127(ro)(G)-- --dict:291/300(ro)(G)-- --dict:19/30(L)-- --dict:2/10(L)--
Current allocation mode is local
GPL Ghostscript 9.04: Unrecoverable error, exit code 1
####################
And the PNG I switched to (and which still causes this error) is located here:
http://www.reportlab.org/media/imadj/data/RLIMG_6845acae97ac366a765e5acb5b8ac27f.PNG
(as suggested in this old thread: http://two.pairlist.net/pipermail/reportlab-users/2009-December/009094.html )
Any ideas why the generated PDFs seem to be malformed? (If you need the output PDF I'm happy to send it, but I'm not sure of the etiquette/procedure regarding attachments.)
Thanks,
Michael
More information about the reportlab-users
mailing list