working on inline image...
This commit is contained in:
parent
e80f5c3fd1
commit
4989ff6297
@ -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
18
tests/inline_image.py
Normal 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')
|
||||
BIN
tests/test_files/inline_image.docx
Normal file
BIN
tests/test_files/inline_image.docx
Normal file
Binary file not shown.
BIN
tests/test_files/inline_image_tpl.docx
Normal file
BIN
tests/test_files/inline_image_tpl.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user