Skip to content

Commit

Permalink
BUG: 'PdfFileWriter' object has no attribute 'stream' (py-pdf#787)
Browse files Browse the repository at this point in the history
Closes py-pdf#670
  • Loading branch information
MartinThoma authored and VictorCarlquist committed Apr 29, 2022
1 parent 21b5294 commit fe3ea7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def _sweepIndirectReferences(self, externMap, data):
self._sweepIndirectReferences(externMap, realdata)
return data
else:
if data.pdf.stream.closed:
if hasattr(data.pdf, "stream") and data.pdf.stream.closed:
raise ValueError("I/O operation on closed file: {}".format(data.pdf.stream.name))
newobj = externMap.get(data.pdf, {}).get(data.generation, {}).get(data.idnum, None)
if newobj is None:
Expand Down
10 changes: 10 additions & 0 deletions Tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,13 @@ def test_io_streams():
writer = PdfFileWriter()
with BytesIO() as output_stream:
writer.write(output_stream)


def test_regression_issue670():
filepath = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
reader = PdfFileReader(filepath, strict=False, overwriteWarnings=False)
for _ in range(2):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(reader.getPage(0))
with open("dont_commit_issue670.pdf", "wb") as f_pdf:
pdf_writer.write(f_pdf)

0 comments on commit fe3ea7f

Please sign in to comment.