Concatenating two text documents using UNO API

Hi. I want to concatenate two text documents into one new file using the UNO API in C++. I want to copy all element types, including text, formulas and images. Any pointers on how I can do this?

Text documents mostly come with lots of styles and other kinds of metadata. There may occur any amount of naming conflicts. Think allone of a page break you will need where the merger occurs.

Did you actually consider the basics sufficiently?

A really general advice could only be to create a zip archive where you import the documents to.

You may also use a new Writer document without specific styles and structure, and import the two msource documents there as OLE objects.

IMO a “concatenation” of arbitrary text documents simply isn’t defined.

Thanks, @Lupp for your reply. A zip file is not what I require here. I am interested in finding how to cat two text docs which might contain text, tables, formulas and images. I did try out a C++ program. However, the pure XText with its getString() method does not suffice for me – this only considers Text elements.

(What do you think is the “pure XText”?)
What you talk about is the problem I tried to address with my first comment.
Did you consider what I told there concerning the problems?
As long as there isn’t a solution concerning the problems I hinted (and more of them) it’s pointless to to tallk 0f C++ or any language to write the code in. None of them has a method to solve the unsolvablle.

Concatenation is defined for plain text. Concatenation of Writer documents with all their contents, structures, styles is not defined. You need to supply the definition first.

The XText is a structure which holds text elements.

We can assume the document to be fairly organized, like one type of element following another.

I would be interested in any method which allows me to iterate over the various types of content, one following the other.

Thanks

In API speak XText is an interface which is implemented in different versions for differently complex types of text.

Writer documents aren’t just a sequence of contents as I already tried to hint. They may contain lots of objects (shapes, frames in specific) coming with their own .Text object. Even every cell of a TextTable supports a full-grown .Text service, TextTables can be nested or be TextContent inside a frame…
There are questions of anchoring and positioning that can’t be resolved without regarding actual styles and what’s called page styles - and many things in addition.
I’m out now.

UPDATE:
If we open LibreOffice writer ver 7.4.5.1, we can Insert > Section… > Link > Link to add arbitrary files at the current cursor position. This is exactly what we want.

How can we get the API to do this?

Do you know master documents (aka global documents)?
To learn about the feature and to see an example you may download the LibreOffice-V7.5-Writer Guide which is itself available as a master document from The Document Foundation Nextcloud
I personally don’t use master documents, and don’t know about dedicated services, interfaces, and structures. You may find something starting here.

Thanks for the links. I will look into them.

Thanks to this (insertDocumentFromURL), concatenating documents has become a simple matter.

If you want to see how to do this in C++, go to my GitHub repo doccat.