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

 1Sub insert_image_in_current_position()
 2
 3    path_image = "/home/mau/Pictures/pymacros.jpg"
 4
 5    doc = ThisComponent
 6    text = doc.CurrentSelection.getByIndex(0).End
 7	
 8    image = doc.createInstance("com.sun.star.text.GraphicObject")
 9    image.GraphicURL = ConvertToURL(path_image)
10    image.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
11    image.Width = 2500
12    image.Height = 2500
13            
14    cursor = doc.Text.createTextCursorByRange(text)
15    doc.Text.insertTextContent(cursor, image, False)
16	
17End Sub

References to API