mirror of
https://github.com/bringout/oca-edi.git
synced 2026-04-20 14:12:05 +02:00
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:
parent
1b3653d8fd
commit
dec5981eb0
3 changed files with 70 additions and 8 deletions
|
|
@ -21,11 +21,19 @@ The pdf_helper module uses PyPDF2 indirectly through:
|
|||
|
||||
## Solution
|
||||
|
||||
**This package requires NO direct patches** because it uses:
|
||||
1. `OdooPdfFileWriter` from `odoo.tools.pdf` (oca-ocb-base)
|
||||
2. `OdooPdfFileReader` from `odoo.tools.pdf` (oca-ocb-base)
|
||||
**This package includes direct fixes** for PyPDF2 3.x page copying issue:
|
||||
1. Uses `OdooPdfFileWriter` from `odoo.tools.pdf` (oca-ocb-base) for compatibility
|
||||
2. **CRITICAL FIX**: Added explicit page copying after `cloneReaderDocumentRoot()`
|
||||
|
||||
The main compatibility layer in `oca-ocb-base` handles all PyPDF2 version compatibility automatically.
|
||||
In PyPDF2 3.x, `cloneReaderDocumentRoot()` only copies document structure, not content pages. This was causing 327-byte empty PDFs. The fix includes 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)
|
||||
```
|
||||
|
||||
## Files Using PyPDF2
|
||||
|
||||
|
|
@ -35,14 +43,14 @@ The main compatibility layer in `oca-ocb-base` handles all PyPDF2 version compat
|
|||
|
||||
### `pdf_helper/models/helper.py`
|
||||
- Uses `OdooPdfFileWriter` and `OdooPdfFileReader` (automatically compatible)
|
||||
- Calls methods like `cloneReaderDocumentRoot()` and `addAttachment()`
|
||||
- **FIXED**: Added explicit page copying after `cloneReaderDocumentRoot()` and `addAttachment()`
|
||||
|
||||
## Implementation Details
|
||||
|
||||
**No code changes needed** in this package. Compatibility is achieved through:
|
||||
**Direct code changes applied** in this package:
|
||||
|
||||
1. **Dependency**: Requires `oca-ocb-base` with `pdfwrite` branch
|
||||
2. **Automatic compatibility**: `OdooPdfFileWriter`/`OdooPdfFileReader` handle all PyPDF2 version differences
|
||||
1. **Dependency**: Requires `oca-ocb-base` with `pdfwrite` branch for compatibility classes
|
||||
2. **Page copying fix**: Added explicit page copying loops in multiple methods
|
||||
3. **Import handling**: Exception imports handle both old and new PyPDF2 locations
|
||||
|
||||
## Testing
|
||||
Loading…
Add table
Add a link
Reference in a new issue