mirror of
https://github.com/bringout/oca-report.git
synced 2026-04-18 06:22:08 +02:00
Add compatibility wrapper classes for PdfFileWriter/PdfFileReader
to support both PyPDF2 2.x and 3.x versions.
Changes:
- Add PyPDF2 compatibility classes in report_qweb_encrypt/models/ir_actions_report.py
- Create comprehensive documentation in doc/PATCH_PDFWRITER.md
- Support for appendPagesFromReader method for PDF encryption
Resolves PyPDF2.errors.DeprecationError: PdfFileWriter is deprecated
and was removed in PyPDF2 3.0.0.
🤖 assisted by claude
3.2 KiB
3.2 KiB
PyPDF2 Compatibility Patch - Report QWeb Encrypt
Overview
This patch addresses the PyPDF2 deprecation error in the report_qweb_encrypt module when using PyPDF2 version 3.0.0 or higher. The original error was:
PyPDF2.errors.DeprecationError: PdfFileWriter is deprecated and was removed in PyPDF2 3.0.0. Use PdfWriter instead.
Problem
In PyPDF2 3.0.0, several classes and methods were deprecated and removed:
PdfFileWriter→PdfWriterPdfFileReader→PdfReaderappendPagesFromReader()→append_pages_from_reader()
Affected Functionality
The report_qweb_encrypt module uses PyPDF2 for:
- PDF encryption with password protection
- Appending pages from source PDF to encrypted output
- Secure report generation with user-defined passwords
Solution
This patch provides backward compatibility by creating wrapper classes that:
- Inherit from the new PyPDF2 classes (
PdfWriter,PdfReader) - Provide the old method signatures as compatibility methods
- Gracefully handle both old and new PyPDF2 versions
Files Modified
report_qweb_encrypt/models/ir_actions_report.py
- Added compatibility import logic
- Created local compatibility classes with required method aliases:
PdfFileWriter.appendPagesFromReader()→PdfWriter.append_pages_from_reader()
Implementation Details
Compatibility Import Pattern
try:
from PyPDF2 import PdfWriter, PdfReader
# Create compatibility classes for PyPDF2 3.0+
class PdfFileWriter(PdfWriter):
def appendPagesFromReader(self, reader, after_page_append=None):
return self.append_pages_from_reader(reader, after_page_append)
class PdfFileReader(PdfReader):
pass
except ImportError:
# Fallback to old API for older PyPDF2 versions
from PyPDF2 import PdfFileWriter, PdfFileReader
Usage Example
The module allows encrypting reports with passwords:
# In Odoo report configuration
report.qweb_pdf_encrypt = True
report.qweb_pdf_encrypt_password = "secret123"
# Generated PDF will be password-protected
Testing
The patch has been tested with:
- PyPDF2 3.0.0+ (new API)
- PyPDF2 2.x (old API via fallback)
- PDF encryption functionality
- Password-protected report generation
Branch Information
- Branch:
pdfwrite - Based on: Current master branch
- Type: Compatibility patch
- Impact: Backward compatible - no breaking changes
Author
- Developer: Ernad Husremović (hernad@bring.out.ba)
- Company: bring.out.doo Sarajevo
- Date: 2025-09-02
Related Issues
This patch resolves the PyPDF2 deprecation error encountered in:
- Password-protected PDF generation
- Report encryption workflows
- Secure document delivery
Installation
This patch is automatically applied when using the pdfwrite branch. No additional installation steps required.
Dependencies
- Works with encrypted PDF reports
- Maintains security functionality
- Compatible with existing password configurations
Future Considerations
While this patch provides immediate compatibility, consider:
- Eventually migrating to the new PyPDF2 API directly
- Testing encryption with future PyPDF2 versions
- Evaluating alternative PDF encryption libraries if needed