Hello,
I'm using Aspose Words, Cells, Slides and Pdf for Java.
I would like to know if Aspose is able to handle particular document before processing the whole document. Is there such a method or any other way to check it? Or can I assume that if Aspose is capable of recognising document type from stream in a way like this: <A href="https://forum.aspose.com/t/25882</A> it is also capable of processing the whole document?</P>
<P>Regards,</P>
<P>Jakub</P>
Hi Jakub,
Thanks for contacting support.
As per my understanding, you need the feature to determine the file type before loading/processing the whole document. As shared in this forum thread, you can use the same code snippet to determine the input file type. In case I am unable to understand your requirement, please share some further details.
Hi Jakub,
Thanks for your inquiry. I would like to address your query regarding Aspose.Words.
Please use the FileFormatUtil.detectFileFormat method to detect the information about a format of a document stored in a disk file. Please check the following code example for your kind reference. http://www.aspose.com/docs/display/wordsjava/How+to++Detect+the+File+Formathttp://www.aspose.com/docs/display/wordsjava/FileFormatInfoThe FileFormatInfo.DetectFileFormat method can detect the document format irrespective of the file extension. It would still return LoadFormat.Unknown value even when you renamed a .pdf document to .doc. However, it does not guarantee that the specified document is valid Word document. This method only detects the document format by reading data that is sufficient for detection.
With FileFormatInfo.DetectFileFormat method, you can detect only file formats listed in the following link:
Hi Jakub,
Thanks for your posting and using Aspose APIs.
I would like to answer your query in Aspose.Cells perspective. Aspose.Cells provides the static FileFormatUtil.detectFileFormat() method which can take input in the form of file path or stream and detect the format of the given file without actually loading it.
You can use this method to detect the file format and also it will help you know if the file is encrypted or not. Please see the following documentation article that illustrates how to make use of this method for your needs.
Here is the equivalent code in Java for your reference.
Java
//Detect file format
FileFormatInfo info = FileFormatUtil.detectFileFormat(“e:\test2\Book1.xlsx”);
//Gets the detected load format
System.
out.println("The spreadsheet format
is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat()));
//Check if the file is encrypted.
System.
out.println("The file
is encrypted: " + info.isEncrypted());