working on inline image...

This commit is contained in:
Eric Lapouyade 2017-01-14 19:42:23 +01:00
parent e80f5c3fd1
commit 4989ff6297
4 changed files with 32 additions and 0 deletions

View File

@ -219,5 +219,19 @@ class RichText(object):
def __str__(self):
return self.xml
class InlineImage(object):
""" class to generate an inline image
This is much faster than using Subdoc class.
"""
def __init__(self, tpl, file, width=None, height=None):
self.xml = '</w:t></w:r></w:p><w:p><w:r><w:drawing>'+tpl.docx._part.new_pic_inline(file, width,height).xml+'</w:drawing></w:r></w:p><w:p><w:r><w:t>'
def __unicode__(self):
return self.xml
def __str__(self):
return self.xml
R = RichText

18
tests/inline_image.py Normal file
View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
'''
Created : 2017-01-14
@author: Eric Lapouyade
'''
from docxtpl import DocxTemplate, InlineImage
from docx.shared import Inches
tpl=DocxTemplate('test_files/inline_image_tpl.docx')
context = {
'myimage' : InlineImage(tpl,'/home/elapouya/tmp/dmozrated.png'),
}
tpl.render(context)
tpl.save('test_files/inline_image.docx')

Binary file not shown.

Binary file not shown.