Insert a comment with custom presets

From The Document Foundation Wiki
< Macros‎ | Writer
Jump to navigation Jump to search


Description

Insert a image in current cursor position in a current document.

Basic code

 1import uno
 2from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
 3
 4
 5def main():
 6
 7    path_image = '/home/mau/Pictures/pymacros.jpg'
 8
 9    doc = XSCRIPTCONTEXT.getDocument()
10    text = doc.CurrentSelection[0].End
11
12    image = doc.createInstance('com.sun.star.text.GraphicObject')
13    image.GraphicURL = uno.systemPathToFileUrl(path_image)
14    image.AnchorType = AS_CHARACTER
15    image.Width = 2500
16    image.Height = 2500
17
18    cursor = doc.Text.createTextCursorByRange(text)
19    doc.Text.insertTextContent(cursor, image, False)
20
21    return

References to API