Merge pull request #593 from aperechnev/master

Possibility to skip missing pictures
This commit is contained in:
Eric Lapouyade 2025-05-02 15:56:50 +02:00 committed by GitHub
commit 08a5d748f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,6 +46,7 @@ class DocxTemplate(object):
self.docx = None
self.is_rendered = False
self.is_saved = False
self.allow_missing_pics = False
def init_docx(self, reload: bool = True):
if not self.docx or (self.is_rendered and reload):
@ -797,10 +798,11 @@ class DocxTemplate(object):
if rel.reltype in (REL_TYPE.HEADER, REL_TYPE.FOOTER):
self._replace_docx_part_pics(rel.target_part, replaced_pics)
# make sure all template images defined by user were replaced
for img_id, replaced in replaced_pics.items():
if not replaced:
raise ValueError("Picture %s not found in the docx template" % img_id)
if not self.allow_missing_pics:
# make sure all template images defined by user were replaced
for img_id, replaced in replaced_pics.items():
if not replaced:
raise ValueError("Picture %s not found in the docx template" % img_id)
def get_pic_map(self):
return self.pic_map