Insert an image at cursor position

    From The Document Foundation Wiki
    < Macros‎ | Writer



    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
        pos = 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
                
        pos.Text.insertTextContent(pos, image, False)
    	
    End Sub

    References to API