fix PyPDF2 3.x page copying issue - prevent 327-byte empty PDFs

Added explicit page copying after cloneReaderDocumentRoot() calls because
PyPDF2 3.x only copies document structure, not content pages.

🤖 assisted by claude
This commit is contained in:
Ernad Husremovic 2025-09-02 19:31:11 +02:00
parent c3d53c6a4d
commit 3f19943cec
3 changed files with 510 additions and 11 deletions

View file

@ -43,6 +43,18 @@ This patch provides backward compatibility by creating wrapper classes that:
## Implementation Details
### Critical PyPDF2 3.x Fix - Page Content Copying
In PyPDF2 3.x, `cloneReaderDocumentRoot()` only copies document structure, NOT content pages. This was causing 327-byte PDFs with no actual content. Modules using this method now include explicit page copying:
```python
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)
```
### Compatibility Import Pattern
```python
try: