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

import uno
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER


def main():

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

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

    image = doc.createInstance('com.sun.star.text.GraphicObject')
    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)

    return

References to API