Defer image attachment
If the Word template does not use the images sent in the template context information, there is no need to insert them into the generated document.
This commit is contained in:
parent
dac4425a1f
commit
35cac9c937
@ -282,21 +282,32 @@ class Listing(object):
|
||||
def __str__(self):
|
||||
return self.xml
|
||||
|
||||
|
||||
class InlineImage(object):
|
||||
""" class to generate an inline image
|
||||
"""Class to generate an inline image
|
||||
|
||||
This is much faster than using Subdoc class.
|
||||
"""
|
||||
def __init__(self, tpl, file, width=None, height=None):
|
||||
image_xml = tpl.docx._part.new_pic_inline(file, width, height).xml
|
||||
self.xml = '</w:t></w:r><w:r><w:drawing>%s</w:drawing></w:r><w:r><w:t xml:space="preserve">' % image_xml
|
||||
tpl = None
|
||||
image_descriptor = None
|
||||
width = None
|
||||
height = None
|
||||
|
||||
def __init__(self, tpl, image_descriptor, width=None, height=None):
|
||||
self.tpl, self.image_descriptor = tpl, image_descriptor
|
||||
self.width, self.height = width, height
|
||||
|
||||
def _insert_image(self):
|
||||
pic = self.tpl.docx._part.new_pic_inline(
|
||||
self.image_descriptor,
|
||||
self.width,
|
||||
self.height
|
||||
).xml
|
||||
return '</w:t></w:r><w:r><w:drawing>%s</w:drawing></w:r><w:r>' \
|
||||
'<w:t xml:space="preserve">' % pic
|
||||
|
||||
def __unicode__(self):
|
||||
return self.xml
|
||||
return self._insert_image()
|
||||
|
||||
def __str__(self):
|
||||
return self.xml
|
||||
|
||||
|
||||
|
||||
|
||||
return self._insert_image()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user