pdfrw icon indicating copy to clipboard operation
pdfrw copied to clipboard

decompressing error: pdfrw:Error -3 while decompressing data: incorrect header check (xx, 0)

Open yangxueliang opened this issue 7 years ago • 10 comments

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

AIG_NRR.pdf

yangxueliang avatar Oct 10 '17 16:10 yangxueliang

By the way, I am using anaconda with python 3.6.2 I can reproduce the issue on Win 7 and Win 10

yangxueliang avatar Oct 10 '17 16:10 yangxueliang

Sorry, no time to look at this at the moment. But decompression is a bit iffy in pdfrw.

pmaupin avatar Oct 27 '17 22:10 pmaupin

Also got the same error, when testing with this pdf, would be nice to see some progress on it!

stathismor avatar Nov 08 '17 16:11 stathismor

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.

screen shot 2018-01-10 at 12 14 34 pm

brand-it avatar Jan 10 '18 20:01 brand-it

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?

karol-gruszczyk avatar Mar 29 '18 22:03 karol-gruszczyk

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!

stathismor avatar Jun 19 '18 08:06 stathismor

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.

stathismor avatar Sep 05 '18 17:09 stathismor

Nothing, huh. Too bad, I am having the same issue...

TrendMend avatar Aug 12 '19 03:08 TrendMend

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:

form_pdf_properties

patchworquill avatar Oct 16 '23 01:10 patchworquill