Pypdf Watermarking Returns Error
Solution 1:
Try writing to a StringIO object instead of a disk file. So, replace this:
outputStream = file("outputs.pdf", "wb")
output.write(outputStream)
outputStream.close()
with this:
outputStream = StringIO.StringIO()
output.write(outputStream) #write merged output to the StringIO object
outputStream.close()
If above code works, then you might be having file writing permission issues. For reference, look at the PyPDF working example in my article.
Solution 2:
I encountered this error when attempting to use PyPDF2
to merge in a page which had been generated by reportlab, which used an inline image canvas.drawInlineImage(...)
, which stores the image in the object stream of the PDF. Other PDFs that use a similar technique for images might be affected in the same way -- effectively, the content stream of the PDF has a data object thrown into it where PyPDF2
doesn't expect it.
If you're able to, a solution can be to re-generate the source pdf, but to not use inline content-stream-stored images -- e.g. generate with canvas.drawImage(...)
in reportlab.
Here's an issue about this on PyPDF2.
Post a Comment for "Pypdf Watermarking Returns Error"