-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"KeyError: 0" when merging PDF page that has content-stream-inline images #196
Comments
Hi there, it seems I have a similar problem, and it also occurs In the case of exactly one input file, operands in On the very bottom of my post you'll find the patch that fixed the call and the traceback:
the script:#!/usr/bin/env python
import PyPDF2
import sys
ppmm = 2.83465
a4xmm = 210
a4ymm = 297
a4xp = a4xmm * ppmm
a4yp = a4ymm * ppmm
def pages (filenames):
for filename in filenames:
inpdf = PyPDF2.PdfFileReader(file(filename,"rb"))
for i in range (inpdf.numPages):
yield (inpdf.getPage (i))
class Writer:
def __init__ (self, outfile):
self.outfile = outfile
self.curpagenum = 0
self.writer = PyPDF2.pdf.PdfFileWriter ()
self.newpage = None
def write (self):
self.writer.write (file (self.outfile, "wb"))
def schurlimerge (self, page):
if self.curpagenum % 6 == 0:
if self.newpage: self.newpage.update ()
self.newpage = self.writer.addBlankPage(a4xp, a4yp)
if self.curpagenum % 2 == 0: offset_y = 0
else: offset_y = a4yp / 2
offset_x = a4xp / 3.0 * ((self.curpagenum / 2) % 3) + a4xp / 3.0
self.newpage.mergeRotatedScaledTranslatedPage (page, 90, 2/3.0, offset_x,offset_y)
self.curpagenum += 1
out = Writer (sys.argv [-1])
for page in pages (sys.argv [1:-1]):
out.schurlimerge (page)
out.write () my patch:
|
Appeared when merging PDFs that have content-stream-inline images This patch was provided by Georg Graf : #196 (comment) Thank you! Closes #196
Appeared when merging PDFs that have content-stream-inline images This patch was provided by Georg Graf : #196 (comment) Thank you! Closes #196
Attempting to merge in a PDF page which has an image stored inline in the content stream raises an error. Here's an example which generates such a PDF with reportlab:
Error:
It looks like
_contentStreamRename
doesn't expect to see a data object in the content stream.It's easy to work around this by replacing
canvas.drawInlineImage
withcanvas.drawImage
-- but the inline variant is a valid PDF that may occur in the wild.The text was updated successfully, but these errors were encountered: