sfneal / PyPDF3

A utility to read and write PDFs with Python
https://pythonhosted.org/PyPDF2/
Other
72 stars 15 forks source link

The "data.pdf" can be of type PdfFileWriter, which does not have a "stream" attribute. #15

Closed ChrisBuergi closed 2 years ago

ChrisBuergi commented 2 years ago

The following code fails to write the output for the second page of the attached PDF. With the fix in the pull request it does work as expected. Although I'm not quite sure if this is just a symptom of another problem that manifests itself there.

from PyPDF3 import PdfFileWriter, PdfFileReader

if __name__ == '__main__':
    input_pdf = PdfFileReader('2022-02-03_regiogis.pdf', strict=True)
    for p in [0, 1]:
        page = input_pdf.getPage(p)
        output_pdf = PdfFileWriter()
        output_pdf.addPage(page)
        with open('Page{}.pdf'.format(p), 'wb') as of:
            output_pdf.write(of)

2022-02-03_regiogis.pdf

ChrisBuergi commented 2 years ago

Thanks for the merge and all the work for PyPDF3.