pdfrw
pdfrw copied to clipboard
decompressing error: pdfrw:Error -3 while decompressing data: incorrect header check (xx, 0)
I have a function to read/fill interactive pdf file as following:
def get_overlay_canvas(template_path: str) -> io.BytesIO:
data = io.BytesIO()
pdf = canvas.Canvas(data)
template = pdfrw.PdfReader(template_path)
for page in template.Root.Pages.Kids:
for field in page.Annots:
label = field.T.strip('(').strip(')')
print(label)
sides_positions = list(map(float,field.Rect))
left = min(sides_positions[0], sides_positions[2])
bottom = min(sides_positions[1], sides_positions[3])
value = user_data.get(label, '')
pdf.drawString(x=left, y=bottom, text=value)
pdf.showPage()
pdf.save()
data.seek(0)
return data
It works well for single page pdf, but when applied to multi-pages, the following error appears:
[ERROR] uncompress.py:80 Error -3 while decompressing data: incorrect header check (3, 0) ERROR:pdfrw:Error -3 while decompressing data: incorrect header check (3, 0)
It seems to be related to zlib decompression, but I dont know how to fix it. Anyway can help to resolve the problem? Thanks. The example pdf is attached
By the way, I am using anaconda with python 3.6.2 I can reproduce the issue on Win 7 and Win 10
Sorry, no time to look at this at the moment. But decompression is a bit iffy in pdfrw.
Also got the same error, when testing with this pdf, would be nice to see some progress on it!
So this might help but I found that inflating your PDF is not possible because it is encrypted. Found this out from the following thread.
This thread is what made me check to see that was the case with your document.

I'm having a lot of issues with that particular error. A lot pdf's cause it. Can we try to resolve it in the next version?
Hey @pmaupin, is there any update on this? I've been encountering this issue a few times, and has started to become noticeable now. If you don't have time, could you maybe guide us in where to look for a solution? Thanks!
I thought I was onto something, I tried the suggestion from this answer, here, but with no success. Maybe this can be useful for someone.
Nothing, huh. Too bad, I am having the same issue...
Still an issue in 2023. No python solution currently works for filing in government forms (tried pypdf, PyPDF2, fillpdf, PyPDFForm... most rely on pdfrw and produce this error). The pdf has the following properties: