Insert a comment with custom presets

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


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

Basic code

import uno
from import AS_CHARACTER

def main():

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

    doc = XSCRIPTCONTEXT.getDocument()
    text = doc.CurrentSelection[0].End

    image = doc.createInstance('')
    image.GraphicURL = uno.systemPathToFileUrl(path_image)
    image.AnchorType = AS_CHARACTER
    image.Width = 2500
    image.Height = 2500

    cursor = doc.Text.createTextCursorByRange(text)
    doc.Text.insertTextContent(cursor, image, False)


References to API