- 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
3.3 KiB
PyPDF2 Compatibility Patch - PDF Helper (EDI)
Overview
This package benefits from the PyPDF2 compatibility fixes implemented in the oca-ocb-base package. The pdf_helper module uses OdooPdfFileWriter and OdooPdfFileReader classes that are automatically compatible with PyPDF2 3.0.0+ through the main compatibility layer.
Problem
In PyPDF2 3.0.0, several classes and methods were deprecated and removed:
PdfFileWriter→PdfWriterPdfFileReader→PdfReader- Various method names changed (e.g.,
addPage()→add_page())
Affected Functionality
The pdf_helper module uses PyPDF2 indirectly through:
OdooPdfFileWriterfor embedding XML attachments in PDFsOdooPdfFileReaderfor extracting XML files from PDF documents- XML-to-PDF embedding for EDI workflows
- PDF parsing and attachment processing
Solution
This package includes direct fixes for PyPDF2 3.x page copying issue:
- Uses
OdooPdfFileWriterfromodoo.tools.pdf(oca-ocb-base) for compatibility - CRITICAL FIX: Added explicit page copying after
cloneReaderDocumentRoot()
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:
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
pdf_helper/utils.py
- Imports
PdfReadErrorwith compatibility handling - Uses
OdooPdfFileReader(automatically compatible)
pdf_helper/models/helper.py
- Uses
OdooPdfFileWriterandOdooPdfFileReader(automatically compatible) - FIXED: Added explicit page copying after
cloneReaderDocumentRoot()andaddAttachment()
Implementation Details
Direct code changes applied in this package:
- Dependency: Requires
oca-ocb-basewithpdfwritebranch for compatibility classes - Page copying fix: Added explicit page copying loops in multiple methods
- Import handling: Exception imports handle both old and new PyPDF2 locations
Testing
The compatibility has been verified with:
- PyPDF2 3.0.0+ (new API)
- PyPDF2 2.x (old API)
- XML embedding in PDFs
- XML extraction from PDFs
- EDI document processing workflows
Branch Information
- Branch:
pdfwrite - Based on: Current master branch
- Type: Dependency compatibility (no direct patches)
- Impact: Automatic compatibility through oca-ocb-base dependency
Dependencies
CRITICAL: This package requires:
oca-ocb-basepackage onpdfwritebranch- The main PyPDF2 compatibility layer must be active
Author
- Developer: Ernad Husremović (hernad@bring.out.ba)
- Company: bring.out.doo Sarajevo
- Date: 2025-09-02
Related Issues
This documentation addresses PyPDF2 compatibility for:
- EDI XML embedding workflows
- PDF attachment processing
- Electronic document interchange
Installation
- Ensure
oca-ocb-baseis using thepdfwritebranch - Use this package's
pdfwritebranch (for documentation compliance) - No additional installation steps required
Future Considerations
- Monitor oca-ocb-base compatibility updates
- Test EDI workflows with future PyPDF2 versions
- Consider direct PyPDF2 usage optimization if needed