JAVA: Identify if pdf and word documents are corrupted/blank?

How do we identify if PDF & WORD documents are corrupted or blank in java?

@rabinintig

In order to determine whether a PDF document is corrupted or not, you can simply use following code snippet with Aspose.PDF for Java:

Boolean IsCorrupt(string path)
{
try
{
Document doc = new Document(path);
}
catch(Exception ex)
{
return true;
}
return false;
}

We will get back to you soon with the information regarding Aspose.Words.

@rabinintig

You can use following code to check either Word document is corrupted or not.

Boolean IsCorrupt(String path)
{
    try
    {
        com.aspose.words.Document doc = new com.aspose.words.Document(path);
    }
    catch(Exception ex)
    {
        return true;
    }
    return false;
}

Following code shows how to check either Word document is blank or not.

Boolean IsEmpty(String path) throws  Exception
{
    com.aspose.words.Document doc = new com.aspose.words.Document(path);
    if(doc.toString(SaveFormat.TEXT).trim().length() == 0
            && doc.getChildNodes(NodeType.SHAPE, true).getCount() == 0)
        return true;
    else
        return false;
}