Using the UI, I can play through the scenario as follows: menu “File → New → Master Document”, then in the Navigator window click “Insert” and select a number of documents. The documents are then loaded into the Master in order of their selection (it seems). Then I use the menu “File → Export” and save the whole thing as .ODT. (See also this thread and few other How-Tos on the interwebs.)

Now I would like to do the same programmatically, but I can’t quite figure out how to get to the “Master Document”. Is it a predefined URL argument to loadComponentFromURL() like e.g. private:factory/swriter?

And once the Master is open, I would load and append multiple documents using loadComponentFromURL() again, using the Master’s frame name? (Which is what, then?)

Once all documents are loaded into the Master, can I then grab a paragraph enumeration of the entire document and noodle over all collected paragraphs and their text portions as outlined in this old thread?

Last edited by _savage on Fri Mar 23, 2018 2:46 am, edited 1 time in total.

As far as I know, a master document is nothing else that a text document with special gui elements to easily manage subdocuments (aka linked sections), indexes, link updates...So inserting a document into another is "as easy as" creating a section linked to that document, then breaking the link if wanted.Something like this, in basic :

So inserting a document into another is "as easy as" creating a section linked to that document, then breaking the link if wanted.

Thank you Hubert, that’s quite interesting. Do you refer to “Sections” as described here?

With some adjusting to Python your proposed code works. However, I am curious how these linked sections handle different document layout and page dimensions when documents are loaded into them. For example, loading just a single DOCX file as a Section into a Master Document looked somewhat crooked compared to loading that same document directly. That may be because the document is now loaded into a Section, thus adjusting to existing document properties?

_savage wrote:However, I am curious how these linked sections handle different document layout and page dimensions when documents are loaded into them.

When you work with master document, it's hardly recommended to used styles : if the subdocument uses a style (of any family) which name exists in the master document, the formatting of the last is used. If the subdocument uses new styles, they are imported in the master document. Direct formatting is always kept.A linked section works exactly the same way.

_savage wrote:For example, loading just a single DOCX file as a Section into a Master Document looked somewhat crooked compared to loading that same document directly.

I never tried this, but it sounds like a very bad idea. Convert the docx to the odf format before doing anything using LibreOffice. If needed, convert back to docx when you finish the editing stuff.

hubert lambert wrote:When you work with master document, it's hardly recommended to used styles : if the subdocument uses a style (of any family) which name exists in the master document, the formatting of the last is used. If the subdocument uses new styles, they are imported in the master document. Direct formatting is always kept. A linked section works exactly the same way.

You mean that the styling and formatting of the imported document overrides the styling and formatting of the Master Document?

That would be the preferred option, actually. In fact, I’d be happy to remove all styling/formatting from the Master Document and use only the that of the imported document(s).

hubert lambert wrote:I never tried this, but it sounds like a very bad idea. Convert the docx to the odf format […]

I don’t have much control over the actual file format because it’s clients’ choice. However, in the case of loading files into the Master Document I think HTML will be what I see most (i.e. HTML and CSS styling).

_savage wrote:You mean that the styling and formatting of the imported document overrides the styling and formatting of the Master Document?

No, on the contrary : master document styles override subdocument styles... when they share the same name.When the style only exists in the subdocument, then it is imported and therefore used by the master document.The master document is responsible for keeping coherence of formatting.