How to actually insert the content of a linked document into an odt file?

I am using an odm document and established links with other documents on my computer. so far so good.
Now I want to create an .odt document that actually contains the referenced documents (nor more “links” please)
when I create and .odt document it stills contains links but I don’t want that: this document is to be edited elsewhere by someone else on a different computer. So it’s impossible to have links. So how to create a new document that contains the content of the links ? (sorry for the clumsy phrasing I am not a native speaker)
thanks

Wouldn’t say “impossible”. You need links relative to the root-document, not absolute links with full path.

1 Like

You can insert the documents you need to incorporate as editable text.

Open the main document, which you will send for further editing.

Click on: Menu —> Insert —> Text from file…

Select the .odt document whose content you want to insert and the complete content of the document will be inserted as editable text.

In this way, the content of the documents to be inserted will be integrated as part of the main document and can be edited on another computer without problems.

this is extremely clumsy: I have almost 50 links.
there should be a way to automatically insert the content of the links.
I experimented a curious turnaround: 1) create a .docx document 2) recreate an .odt document from the .docx … It looks like its working (I just changed the name of the directory at the top of the linked files and though the .odm or the initial .odt do not find the links anymore the doctored .odt seems happy with that… still need to test and re-test this strange behaviour.

What you need then is how to convert the links to 50 .odt documents into editable text, for this you need a macro, something like the following:

Sub InsertLinkedDocuments()
    Dim oDoc As Object
    Dim oLinks As Object
    Dim i As Integer
    Dim sFilePath As String
    Dim oCursor As Object
    Dim oText As Object
    Dim oFile As Object

    oDoc = ThisComponent
    oLinks = oDoc.getTextFields()

    For i = oLinks.getCount() - 1 To 0 Step -1
        oFile = oLinks.getByIndex(i)
        If oFile.supportsService("com.sun.star.text.TextField.URL") Then
            sFilePath = oFile.URL
            sFilePath = ConvertFromURL(sFilePath)

            ' Replace the link with the file content
            oCursor = oDoc.Text.createTextCursorByRange(oFile.Anchor)
            oText = oDoc.Text
            oText.insertString(oCursor, ReadFile(sFilePath), False)
            
            ' Remove the hyperlink field
            oDoc.TextFields.removeByIndex(i)
        End If
    Next i

    MsgBox "All linked documents have been inserted as editable text.", 64, "Process Completed"
End Sub

Function ReadFile(sFilePath As String) As String
    Dim oFile As Object
    Dim sContent As String
    Dim oInputStream As Object

    oFile = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
    
    If oFile.Exists(sFilePath) Then
        oInputStream = oFile.openFileRead(sFilePath)
        Dim sLine As String
        Do
            sLine = oInputStream.readLine()
            sContent = sContent & sLine & Chr(10)
        Loop Until sLine = ""
        oInputStream.closeInput()
    Else
        sContent = "Could not open: " & sFilePath
    End If
    
    ReadFile = sContent
End Function

In general terms, to create a macro:

Open the main document.

Pressing Alt + F11 should open the macro editor.

Selecting the document and clicking “New” should create a module.

Copying and pasting the code should complete it.

To save and run the macro press F5 in the macro editor.

All linked documents should be inserted as editable text.

thanks
but still some questions:

  • the linked documents are all .odt files: will they be inserted as such (with all formating info?)
  • how to use such a macro? (not familiar with such kludges)
    thanks

I think using the command line should work, soffice.exe --convert-to odt my_document.odm.
I have not tried it but see Starting LibreOffice Software With Parameters