简体   繁体   English

PyPDF2 这是一个错误吗?

[英]PyPDF2 is this a bug?

Here is a simple very easily reproducible example of the bug I am having in PyPDF2.这是我在 PyPDF2 中遇到的错误的一个简单且非常容易重现的示例。 Please help me figure out what is going on.请帮我弄清楚发生了什么事。

I want to generate this pdf:我想生成这个 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.但是,只有在 mac viewer 或 safari 中查看时才会看起来像这样。 When I view THE SAME FILE in google chrome or brave or adobe I see this:当我在 google chrome 或 brave 或 adobe 中查看相同的文件时,我看到了这个:

So page 2 just shows page 1 again.所以第 2 页再次显示第 1 页。 If I do n pages then all n pages are identical and they all say "page 1".如果我做 n 页,那么所有 n 页都是相同的,它们都说“第 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.我希望它可以在 chrome、brave、adobe 中正确查看,并且在许多其他人中也可能是错误的。

#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.是的,这是 PyPDF2 中的错误。 We have issues with filling out forms for a long time, see https://github.com/py-pdf/PyPDF2/issues/355我们长期填表有问题,见https://github.com/py-pdf/PyPDF2/issues/355

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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