eea / odfpy

API for OpenDocument in Python
GNU General Public License v2.0
311 stars 64 forks source link

Problem with drawing subobject #74

Open zimakim opened 6 years ago

zimakim commented 6 years ago

I want to add drawing subobject to text file. This code generate incorrect odt file. What problem with it? As an example I used subobject.py

from odf.opendocument import OpenDocumentText, OpenDocumentDrawing
from odf import text, style, draw

def gen_drawing(imageloc):
    drawingdoc = OpenDocumentDrawing()
    page = draw.Page(masterpagename = u"new")
    drawingdoc.drawing.addElement(page)
    frame = draw.Frame(layer = 'layout', height="20cm", width="20cm")
    page.addElement(frame)
    href = drawingdoc.addPicture(imageloc)
    print href
    im = draw.Image(href = href)
    frame.addElement(im)
    drawingdoc.save(u'test.odg')
    return drawingdoc

subobject = gen_drawing(u'test.png')
maindoc = OpenDocumentText()
p = text.P()
maindoc.text.addElement(p)
df = draw.Frame(width="21cm", height="21cm", anchortype="paragraph")
p.addElement(df)
objectloc = maindoc.addObject(subobject)
print objectloc
do = draw.Object(href=objectloc)
df.addElement(do)
maindoc.save("mydocument.odt")
rapto commented 4 years ago

It works for me (I added the parenthesis in the print call to test in py38)