Skip to content

Commit

Permalink
[FIX] pdf_helper: Odoo compatibility
Browse files Browse the repository at this point in the history
Related to odoo/odoo@fddf53c#diff-b6e108b605fbefba066e3b20f8e030ea78881bbed816f8ac5cb38e745c542739R8

Co-Authored-By: Pedro M. Baeza <pedro.baeza@tecnativa.com>
  • Loading branch information
victoralmau and pedrobaeza committed Oct 25, 2024
1 parent c5da9c3 commit 522d412
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pdf_helper/models/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging

from odoo import api, models
from odoo.tools.pdf import NameObject, OdooPdfFileReader, OdooPdfFileWriter
from odoo.tools.pdf import NameObject, PdfFileReader, PdfFileWriter

from ..utils import PDFParser

Expand Down Expand Up @@ -38,8 +38,8 @@ def pdf_get_xml_files(self, pdf_file):
def pdf_embed_xml(self, pdf_content, xml_filename, xml_string):
"""Add an XML attachment in a pdf"""
with io.BytesIO(pdf_content) as reader_buffer, io.BytesIO() as new_pdf_stream:
reader = OdooPdfFileReader(reader_buffer, strict=False)
writer = OdooPdfFileWriter()
reader = PdfFileReader(reader_buffer, strict=False)
writer = PdfFileWriter()
writer.cloneReaderDocumentRoot(reader)
writer.addAttachment(xml_filename, xml_string, subtype="text/xml")
# show attachments when opening PDF
Expand Down
7 changes: 1 addition & 6 deletions pdf_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

from lxml import etree

try:
from PyPDF2.errors import PdfReadError
except ImportError:
from PyPDF2.utils import PdfReadError

from odoo.tools.pdf import OdooPdfFileReader
from odoo.tools.pdf import OdooPdfFileReader, PdfReadError

_logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 522d412

Please sign in to comment.