Page 1 of 1

[Solved] storeToURL with Contents of Master Document

PostPosted: Fri Feb 24, 2017 5:05 pm
by gareththered
I've a Python script which opens a Master Document and updates it, so that I can save the document in various formats.

The issue I have is that while saving as a PDF or an MS Word (docx) saves fine as a standalone document, saving as a Writer (odt) still saves with links. That means that the output document cannot (for example) be emailed to anyone as they won't have access to the original linked sub-documents.

The Navigator pane (F5) has a Save Content as well button, but I can't figure out how to do this with UNO.

Snippets of Python I'm using are:

Code: Select all   Expand viewCollapse view
# Start a headless instance of libreoffice, then:

import uno
from import PropertyValue

localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("", localContext)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
svcmgr = context.ServiceManager
desktop = svcmgr.createInstanceWithContext("", context)

model = desktop.loadComponentFromURL('file:///home/gareth/Master.odm', "_blank", 0, ())

model.text.getString() # so that I can see it's updated

args = (PropertyValue('FilterName',0,'MS Word 2007 XML',0),)

args = (PropertyValue('FilterName',0,'writer_pdf_Export',0),)

# This next one is the problem:
args = (PropertyValue('FilterName',0,'writer8',0),)

test.odt still has links to the original sub-documents.

Does anyone know the code required to force contents to be saved in the file instead of the link?

Re: storeToURL with Contents of Master Document

PostPosted: Sat Feb 25, 2017 3:07 pm
by hubert lambert

As a very first export, you may do this :
1. call dispose() on all sections of your master document (this will remove all the links);
2. save the master document AS a new odt document (storeAsURL method to leave the master doc untouched).

Then you can proceed with further exports the way you did.

[SOLVED] storeToURL with Contents of Master Document

PostPosted: Sat Feb 25, 2017 9:55 pm
by gareththered
Thanks @hubert - that did the trick.

Just for the benefit of anyone who arrives here, the code that does this is:

Code: Select all   Expand viewCollapse view
sections = model.Links.Sections
for name in sections:

Both storeToURL as well as storeAsURL seems to work after running the above.