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

Sub insert_image_in_current_position()

    path_image = "/home/mau/Pictures/pymacros.jpg"

    doc = ThisComponent
    text = doc.CurrentSelection.getByIndex(0).End
	
    image = doc.createInstance("com.sun.star.text.GraphicObject")
    image.GraphicURL = ConvertToURL(path_image)
    image.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
    image.Width = 2500
    image.Height = 2500
            
    cursor = doc.Text.createTextCursorByRange(text)
    doc.Text.insertTextContent(cursor, image, False)
	
End Sub

References to API