Hello!
I have regular text and I have a textframe, which I want to send “wrap in background”.
Apparently this cannot be set via setPropertyValue.
Difficulty is I invoke writer headless.
Macro recording suggest the use of dispatcher.executeDispatch.
My suspicion is the problem is with line:
dispatcher.executeDispatch(model.CurrentController.Frame, “.uno:WrapThroughTransparencyToggle”, “”, 0, ())
Any help appreciated,
Robert
#!/bin/python
# -*- coding: utf-8 -*-
# coding: utf8
import uno
import unohelper
import os
import time
from com.sun.star.text.WrapTextMode import THROUGHT as WrapTextModeTHROUGHT
from com.sun.star.text.TextContentAnchorType import AT_PARAGRAPH
from com.sun.star.beans import PropertyValue
from com.sun.star.awt import Size
def rgb(r, g, b):
return 256*256*r + 256*g + b
os.system("libreoffice --headless --accept='socket,host=localhost,port=2002,tcpNoDelay=1;urp' --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &")
time.sleep(1)
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", localContext )
smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)
dispatcher = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", remoteContext)
ccontext = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
text = doc.Text
cursor = text.createTextCursor()
cursor.CharColor = rgb(0, 0, 0)
textFrame = doc.createInstance( "com.sun.star.text.TextFrame" )
textFrame.setSize( Size(17000,17000))
model = desktop.getCurrentComponent()
textFrame.setPropertyValue( "AnchorType" , AT_PARAGRAPH )
textFrame.setPropertyValue( "AnchorPageNo", 1 )
textFrame.HoriOrient = 0
textFrame.HoriOrientPosition = 5
textFrame.HoriOrientRelation = 6
textFrame.setPropertyValue( "TextWrap", WrapTextModeTHROUGHT )
# Functionality wrap "in background" needs to be invoked
dispatcher.executeDispatch(model.CurrentController.Frame, ".uno:WrapThroughTransparencyToggle", "", 0, ())
#
noLine = uno.createUnoStruct( "com.sun.star.table.BorderLine2" )
noLine.LineStyle = uno.getConstantByName("com.sun.star.table.BorderLineStyle.NONE")
noLine.LineWidth = 0
text.insertTextContent( cursor, textFrame, 0 )
textFrame.TopBorder = textFrame.RightBorder = textFrame.BottomBorder = textFrame.LeftBorder = noLine
solidLine = uno.createUnoStruct( "com.sun.star.table.BorderLine2" )
solidLine.LineStyle = uno.getConstantByName("com.sun.star.table.BorderLineStyle.SOLID")
solidLine.LineWidth = 10
textInTextFrame = textFrame.getText()
cursorInTextFrame = textInTextFrame.createTextCursor()
cursorInTextFrame.CharHeight = 9
cursorInTextFrame.CharColor = rgb(0, 0, 255)
text.insertString(cursor, "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", 0)
textInTextFrame.insertString( cursorInTextFrame, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed dolor pellentesque nunc accumsan cursus at ac risus. Sed tincidunt erat a metus rutrum, nec vestibulum nisl vulputate. Donec eu elit vel dui dictum bibendum. Ut quis iaculis tortor. Sed efficitur, elit vel fringilla ullamcorper, elit tortor rutrum purus, eu dapibus risus mi quis sem. Integer elementum turpis eu vehicula porta. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla pharetra id lorem a ultrices. Aliquam ante mauris, luctus porta mollis ac, laoreet id leo. Vivamus a molestie est, et tempor purus. Nam eget accumsan lacus. Nullam consequat convallis lectus, eu commodo tellus lobortis non.",0)
properties = (PropertyValue("FilterName", 0, "writer8", 0), PropertyValue("Overwrite", 0, True, 0),)
doc.storeToURL('file:///tmp/test.odt', properties )
doc.dispose()
os.system("killall soffice.bin &")