This is a problem I get on any document I process, but you can use as an example one of your files from the Java package. For this post I used SalesInvoiceDemo.doc (docx documents do not work as well).
Make a simple tree-walk algorithm that takes each node of the document and calls toTxt if node type is Run, like this
public void traverseAllNodes(CompositeNode parentNode) throws Exception
{
for (Node childNode = parentNode.getFirstChild(); childNode != null; childNode = childNode.getNextSibling())
{
Run run = (Run) childNode;
String runStr = run.toTxt();
if (childNode.isComposite())
traverseAllNodes((CompositeNode)childNode);
}
}
Calling to run.toTxt will eventually (sometimes at the first iteration) cause exception:
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:85)
at com.aspose.words.awm.visitRun(TxtWriter.java: 109)
at com.aspose.words.Run.accept(Run.java: 89)
at com.aspose.words.awm.v(TxtWriter.java: 68)
at com.aspose.words.Document.a(Document.java: 1378)
at com.aspose.words.Node.toTxt(Node.java: 588)
For the document I' ve mentioned exception pops at the run with text "PAGE * MERGEFORMAT"
Thanks for your query. It would be great, If you share what you want to do by using Aspose.Words? The code shared by you will not work because you are casting each childNode to Run, which is incorrect. Please see the different types of nodes in document explorer.
Hi
Thanks for your request. Yes, we are aware of this issue. We will let you know once this problem is resolved.
You can use Run.getText() instead of Run.toTxt() while you are waiting for a fix.
Best regards,