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

Free Support Forum - aspose.com

How can I handle document just like the ‘string.trim()' function

I want to handle document just like the ‘string.trim()’ function.
" abc ".trim() = “abc”

I made a recursive method to delete the paragraphs with empty text before and after the document.But if it has image it will be remove also.I can judge if there is a shape node.
But maybe it has another Node which text’s length is empty? How can I solve it.


Thanks for your inquiry. Please use the following code example to get desired results.

Document doc = new Document(“D:\Temp\input.docx”);

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
    bool otherNodeExist = false;

    foreach (Node node in para.GetChildNodes(NodeType.Any, true))
         if (node.NodeType != NodeType.Run)
             otherNodeExist = true;

     if (!para.HasChildNodes || (para.ToString(SaveFormat.Text).Trim().Equals("") && !otherNodeExist))


Hope, this helps.