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

Free Support Forum - aspose.com

Detecting data on a HTML document

I want to convert a document from HTML to PDF only if there is data. Is there a way to detect if there is anything to display before converting?

Hi there,

Thanks for your inquiry. Please use the following code example to achieve your requirements. Hope this helps you.

Boolean ishasdata = false;
Document doc = new Document(MyDir + "in (2).html");
if (doc.ToString(SaveFormat.Text).Trim() != "")
    ishasdata = true;
if (doc.GetChildNodes(NodeType.Shape, true).Count > 0 || doc.GetChildNodes(NodeType.DrawingML, true).Count > 0)
    ishasdata = true;
if (ishasdata)
    doc.Save(MyDir + "Out.pdf");

Please note that Aspose.Words is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects
more like an XML DOM tree. If you worked with any XML DOM library you
will find it is easy to understand and work with Aspose.Words. When you
load a Word document into Aspose.Words, it builds its DOM and all
document elements and formatting are simply loaded into memory. Please
read the following articles for more information on DOM: