简体   繁体   中英

PyPDF2 is this a bug?

Here is a simple very easily reproducible example of the bug I am having in PyPDF2. Please help me figure out what is going on.

I want to generate this pdf:

As you can see, I have generated it so the code is working correctly. However, it looks like this only when viewed in mac viewer or safari. When I view THE SAME FILE in google chrome or brave or adobe I see this:

So page 2 just shows page 1 again. If I do n pages then all n pages are identical and they all say "page 1".

I put all the versions of the software I am using in the comments below. I want this to be viewable correctly in chrome, brave, adobe, and it's probably wrong in many others as well.

#find original pdf page here and save it in "path": https://www.irs.gov/pub/irs-pdf/f8949.pdf
from PyPDF2 import PdfReader, PdfWriter  #, PdfFileMerger, PdfFileWriter, PdfFileReader
writer = PdfWriter()

reader = PdfReader(path)
page = reader.pages[0]
writer.add_page(page)
writer.update_page_form_field_values(writer.pages[0], {"f1_3[0]":"page1"})

reader = PdfReader(path)
page = reader.pages[0]
writer.add_page(page)
writer.update_page_form_field_values(writer.pages[1], {"f1_3[0]":"page2"})

with open("output.pdf", "wb") as output_stream:
        writer.write(output_stream)
        output_stream.close()


#PyPDF2==2.11.2
#PyPDF4==1.27.0
#Python 3.9.7
#Mac 12.1
#Brave 1.45.127
#Adobe 2022.003.20258


#safari good
#preview good

#google bad
#adobe bad
#brave bad

Yes, this is a bug in PyPDF2. We have issues with filling out forms for a long time, see https://github.com/py-pdf/PyPDF2/issues/355

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM