Convert DOCX with revisions to TXT

Aspose.Words for Java v17.6

Hi,

I am trying to convert a docx with revisions to txt, but Aspose doesn´t obey revisions. How to fix that?
I am sending the code and the files that reproduces the problem.

Download.zip (10.1 KB)

import java.nio.charset.Charset;

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.aspose.words.SaveOptions;
import com.aspose.words.TxtSaveOptions;

public class Test {

public static void main(String[] args) throws Exception {
    Document dstDoc = new Document("E:\\Download\\TestDocxToTxt.docx");
    dstDoc.save("E:\\Download\\TestDocxToTxt.txt", createSaveOptions());

}

public static SaveOptions createSaveOptions() {
    TxtSaveOptions txtso = new TxtSaveOptions();
    txtso.setUpdateFields(false);
    txtso.setPrettyFormat(true);
    txtso.setExportHeadersFooters(false);
    txtso.setSaveFormat(SaveFormat.TEXT);
    txtso.setEncoding(Charset.forName("Cp1252"));
    return txtso;
}

}

@cpatricio76,

Thanks for your inquiry. You can get the output shared in TestDocxToTxtconvertedUsingWord.txt by calling Document.acceptAllRevisions method after loading the document. This method accepts all tracked changes in the document.

If this does not help you, please share your expected output TXT document here for our reference. We will then provide you more information about your query.

Document doc = new Document(MyDir + "TestDocxToTxt.docx");
doc.acceptAllRevisions();
TxtSaveOptions txtso = new TxtSaveOptions();
txtso.setUpdateFields(false);
txtso.setPrettyFormat(true);
txtso.setExportHeadersFooters(false);
txtso.setSaveFormat(SaveFormat.TEXT);
txtso.setEncoding(Charset.forName("Cp1252"));

doc.save(MyDir + "output.txt", txtso);

Best Regards,
Tahir Manzoor

@tahir.manzoor

Thank you for you quick answer Tahir. Revisions are OK.

How about comments? How to manage them?
Please see attached the files with Aspose conversion and Word conversion.
Comments.zip (12.0 KB)

@cpatricio76,

Thanks for your inquiry. Please use the following code example to convert DOCX to TXT file format as shown in TestDocxToTxtWithCommentsConvertedUsingWord.txt. Hope his helps you.

Document doc = new Document(MyDir + "TestDocxToTxtWithComments.docx");
doc.acceptAllRevisions();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.writeln();
// Collect all comments in the document
NodeCollection comments = doc.getChildNodes(NodeType.COMMENT, true);

int i = 1;
// Look through all comments and gather information about them.
for (Comment comment : (Iterable<Comment>) comments) {
    builder.moveTo(comment);
    builder.write("[CMP" + i + "]");
    builder.moveToDocumentEnd();
    builder.write("[CMP" + i + "]");
    builder.writeln(comment.toString(SaveFormat.TEXT));
    comment.remove();
    i++;
}
TxtSaveOptions txtso = new TxtSaveOptions();
txtso.setUpdateFields(false);
txtso.setPrettyFormat(true);
txtso.setExportHeadersFooters(false);
txtso.setSaveFormat(SaveFormat.TEXT);
txtso.setEncoding(Charset.forName("Cp1252"));
doc.save(MyDir + "output.txt", txtso);

Best Regards,
Tahir Manzoor

@tahir.manzoor

Is there a way to get the name of the person who wrote the comment?
Let’s say a comment like below:

Alexander Bravo Lima: Testing comment

It is expected:

[ABL1] Testing comment

@tahir.manzoor

Don’t worry. I have found the solution. It is comment.getInitials().

Thank you for your quick support.

@cpatricio76,

It is nice to hear from you that you have found the solution of you query. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Best Regards,
Tahir Manzoor