pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

Filled form data not showing in acroread due to no ability to remove PDF usage rights

Open rdgraham opened this issue 8 years ago • 4 comments

When using the updatePageFormFieldValues to input data to PDF forms, the new data can not be seen when the PDF is opened with acrobat reader (other PDF readers work fine).

This appears to be a known issue due to PDF containing a hash signed with adobe's key which no longer matches, described here: http://what-when-how.com/itext-5/preserving-the-usage-rights-of-reader-enabled-forms-itext-5/

It looks like the iText java library solves this by providing a function to strip out the usage rights. It would be nice if pypdf2 could have a similar function.

Relevant code line 3965 in https://github.com/itext/itextpdf/blob/6197e5e0a5859dd2efd8d8059e87d188f17ea11b/src/main/java/com/itextpdf/text/pdf/PdfReader.java

rdgraham avatar Sep 16 '15 22:09 rdgraham

I'd like to bump this, as it is a fairly big flaw that would be pretty easy to fix.

oscardssmith avatar Aug 08 '16 16:08 oscardssmith

Removing the /Perms data is simple enough; however, it's causing some issues during the write process (at least in the files I'm testing). Currently working to fix that; sending me any 'reader-enabled' form PDFs you have would be helpful.

mstamy2 avatar Aug 12 '16 17:08 mstamy2

Attached is my code, a sample pdf How can I attach the fdf for it?

doc=pdf.PdfFileReader(pdf_path,strict=False)
output=fill_form(doc, fdf_path)
with open(out_path, 'w') as f:
    output.write(f)

def fill_form(doc, fdf):
    field = {}
    if fdf in ('-', 'PROMPT'):
        fdf = input('Input file: ')
    else:
        try:
            with open(fdf, 'r') as in_path:
                for line in in_path.readlines()[4:-11]:
                    field[line.partition('/T')[2].partition('/V')[0].strip()[1:-1]] = line.partition('/V')[2].partition('>>')[0].strip()[1:-1]
        except Exception:
            pass
    output = pdf.PdfFileWriter()
    output.appendPagesFromReader(doc)
    output.updatePageFormFieldValues(output.getPage(0), field)
    return output

oscardssmith avatar Aug 12 '16 18:08 oscardssmith

I'm having the same issue and cannot find the solution. I don't understand your solution! You are just reading the fields from fdf file instead of another source. It doesn't solve the issue.

Mahdi-Hosseinali avatar Nov 17 '17 16:11 Mahdi-Hosseinali

@MartinThoma

  • no detailed code/pdf to reproduce
  • fix refered I propose to close this issue.

pubpub-zz avatar Sep 03 '22 12:09 pubpub-zz

I think the issue here is actually reported in different forms in several places:

  • https://github.com/py-pdf/PyPDF2/issues/300
  • https://github.com/py-pdf/PyPDF2/issues/299
  • https://github.com/py-pdf/PyPDF2/issues/355

I think the title of 355 is clearest. Maybe I'll create a very clear example from all of the above.

For the moment, I close #227 as a duplicate of #355

MartinThoma avatar Sep 06 '22 19:09 MartinThoma