We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HideenText in Run

Hi Aspose,

In this document, when I am using run.getText(), I am getting the hidden texts also. I need a way in which I can ignore reading only this type of hidden texts present in the document and this text is not coming while using para.getText().

PFB details:

Body text–>No table of contents entries found.

runtext–> TOC \o “1-3” \h \z \u
runtext–>No table of contents entries found.

The yellow color highlighted text is the hidden text that we can see via run class.


Hi Rajesh,

Thanks for your inquiry. Please note that ‘TOC \o “1-3” \h \z \u’ are field codes of TOC field. This is not hidden text.

Please use following code example to achieve your requirements and get the code of FieldsHelper class from Aspose.Words for Java examples repository at GitHub.

We suggest you please read the following article for your kind reference.
How to Replace Fields with Static Text

Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + “Test_Dallas.docx”);<o:p></o:p>

//Remove "Table of Authorities" field.

for(Field field : doc.getRange().getFields())


if (field.getType() == FieldType.FIELD_TOA_ENTRY)





if(doc.toString(SaveFormat.TEXT).contains("No table of contents entries found."))

FieldsHelper.convertFieldsToStaticText(doc, FieldType.FIELD_TOC);

NodeCollection runs = doc.getChildNodes(NodeType.RUN, true);

for (Run run : (Iterable)runs)