-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import io | ||
import logging | ||
|
||
from odoo import api, models | ||
from odoo.tools.pdf import OdooPdfFileReader, OdooPdfFileWriter | ||
|
||
from ..utils import PDFParser | ||
|
||
|
@@ -29,5 +31,19 @@ def pdf_get_xml_files(self, pdf_file): | |
try: | ||
return parser.get_xml_files() | ||
except parser.get_xml_files_swallable_exceptions() as err: | ||
# TODO: can't we catch specific exceptions? | ||
# This try/except block was added to reflect what done | ||
# in base_business_document_import till now. | ||
_logger.error("PDF file parsing failed: %s", str(err)) | ||
return {} | ||
|
||
@api.model | ||
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() | ||
writer.cloneReaderDocumentRoot(reader) | ||
writer.addAttachment(xml_filename, xml_string, subtype="text/xml") | ||
writer.write(new_pdf_stream) | ||
return new_pdf_stream.getvalue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters