Hello,
I am trying to convert html string to plain text but its not preserving the styling (indentation, table structure) in converted version. Can you please help me to identify how we can achieve that? I am using below code for conversion.
using (var HtmlDocument = new HTMLDocument(summaryHtml, ""))
{
// Initialize the instance of node iterator to iterate HTML
INodeIterator iterator = HtmlDocument.CreateNodeIterator(HtmlDocument, NodeFilter.SHOW_TEXT
, new StyleFilter());
StringBuilder Stringbld = new StringBuilder();
Aspose.Html.Dom.Node node;
// Iterate through Nodes
while ((node = iterator.NextNode()) != null)
Stringbld.Append(node.NodeValue);
return Stringbld.ToString();
}
class StyleFilter : NodeFilter
{
public override short AcceptNode(Aspose.Html.Dom.Node node)
{
// In order to avoid any element during fetching nodes, write the name of element in capital letters
return (node.ParentElement.TagName == "STYLE" || node.ParentElement.TagName == "SCRIPT"
? FILTER_REJECT : FILTER_ACCEPT);
}
}