fix PyPDF2 3.x page copying + rename documentation

- Added explicit page copying after cloneReaderDocumentRoot() calls
- Renamed PATCH_PDFWRITER.md to PATCH_PYPDF2_PDFWRITER.md
- Prevents 327-byte empty PDFs in PyPDF2 3.x

🤖 assisted by claude
This commit is contained in:
Ernad Husremovic 2025-09-02 19:31:36 +02:00
parent 1b3653d8fd
commit dec5981eb0
3 changed files with 70 additions and 8 deletions

View file

@ -41,6 +41,10 @@ class PDFHelper(models.AbstractModel):
reader = OdooPdfFileReader(reader_buffer, strict=False)
writer = OdooPdfFileWriter()
writer.cloneReaderDocumentRoot(reader)
# Copy all pages from the reader to the writer (required for PyPDF2 3.x)
for page_num in range(reader.getNumPages()):
page = reader.getPage(page_num)
writer.addPage(page)
writer.addAttachment(xml_filename, xml_string, subtype="text/xml")
# show attachments when opening PDF
writer._root_object.update(