>>> with PdfReader("./sample-files/001-trivial/minimal-document.pdf") as reader:
... with PdfWriter(reader) as writer:
... print(writer.fileobj)
...
__init__
__enter__
__init__
<pypdf._reader.PdfReader object at 0x10304e970>
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/Users/mpeveler/code/github/pypdf/pypdf/_writer.py", line 373, in __exit__
self.write(self.fileobj)
File "/Users/mpeveler/code/github/pypdf/pypdf/_writer.py", line 1396, in write
self.write_stream(stream)
File "/Users/mpeveler/code/github/pypdf/pypdf/_writer.py", line 1367, in write_stream
object_positions, free_objects = self._write_pdf_structure(stream)
File "/Users/mpeveler/code/github/pypdf/pypdf/_writer.py", line 1500, in _write_pdf_structure
stream.write(self.pdf_header.encode() + b"\n")
AttributeError: 'PdfReader' object has no attribute 'write'
I'm not sure what the correct behavior here should be, especially with regards to cloning. Like, if I call:
with PdfWriter("foo.pdf") as writer:
Originally posted by @MasterOdin in #2905 (comment)