-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
27 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 | ||
|
||
|
@@ -31,3 +33,14 @@ def pdf_get_xml_files(self, pdf_file): | |
except parser.get_xml_files_swallable_exceptions() as err: | ||
_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