I am embedding an image in a writer document using Python3. I just can’t figure out how to set the image to the original size.
import uno
import unohelper
# a UNO struct later needed to create a document
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
from com.sun.star.awt import Size
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)
# open a writer document
doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
text = doc.Text
cursor = text.createTextCursor()
text.insertString( cursor, "The first line in the newly created text document.\n", 0 )
text.insertString( cursor, "Now we are in the second line\n" , 0 )
# create a text table
table = doc.createInstance( "com.sun.star.text.TextTable" )
# with 4 rows and 4 columns
table.initialize( 4,4)
text.insertTextContent( cursor, table, 0 )
rows = table.Rows
img = doc.createInstance('com.sun.star.text.TextGraphicObject')
img.GraphicURL = 'file:///home/reuben/reuben.jpg'
tableText = table.getCellByName( "C2" )
cursor = tableText.createTextCursor()
tableText.insertTextContent(cursor, img, False)
img.setPropertyValue('AnchorType', AS_CHARACTER)
img.setSize(????)
Any suggestions? Thanks.
[Edit] LO skews the image size sometimes, and I want it to be the original size. The problem is I don’t know what the original size was.