Getting text whilst retaining it's formatting

Hi
I was trying to retrieve formatted text from a document (in order to pass into another document, keeping it’s text formatting) using the following article:
https://docs.aspose.com/words/net/how-to-extract-selected-content-between-nodes-in-a-document/
I created the DocToTxtWriter Class and tried to copy formatted text using the code below.
Unfortunately the resulting text that is printed (docToTxtWriter.GetText) seems to be blank. The document definitely has text in it. Is there something else I have to do or am I missing something?
Many thanks,

public void ToText(String documentDir, String documentName) throws Exception
{
    // Open the document we want to convert.
    Document doc = openDocument(documentDir,documentName);
    // Create an object that inherits from the DocumentVisitor class.
    DocToTxtWriter docToTxtWriter = new DocToTxtWriter();
    doc.accept(docToTxtWriter);
    System.out.println(docToTxtWriter.GetText()); 
}

Hi

Thanks for your request. Actually, this code gets plain text from the document. But you mentioned that you need to insert formatted text.
I think the following articles could be more useful for you.
https://docs.aspose.com/words/java/insert-and-append-documents/
https://docs.aspose.com/words/net/insert-and-append-documents/
Best regards.

Thanks again Alexey,
very much appreciated.