I’m just curious the difference in how Aspose handles doc and docx file extensions, and to be more specific, how to detect which type of file was originally loaded. Is this possible, or is it converted to the same Aspose document structure formatting irregardless of original input type?
Hi Eddie,
Thanks for your query.
The Document Opens an existing document from a file/stream and automatically detects the file format either it is Doc or Docx. The Document is a central class in Aspose.Words and represents a document and provides various document properties and methods such as saving or protecting the document.
You can use FileFormatInfo.DetectFileFormat/Document.getOriginalLoadFormat method to detect document’s format. Please read following documentation links for your kind reference and let us know if you have any more quereis.
https://reference.aspose.com/words/java/com.aspose.words/loadformat
https://reference.aspose.com/words/java/com.aspose.words/fileformatutil/
https://reference.aspose.com/words/java/com.aspose.words/FileFormatInfo
https://reference.aspose.com/words/java/com.aspose.words/Document
Please see the following code snippet for your kind reference.
// Load the document without a file extension into a stream and use the DetectFileFormat method to detect it's format. These are both times where you might need extract the file format as it's not visible
FileInputStream docStream = new FileInputStream(getMyDir() + "Document.FileWithoutExtension"); // The file format of this document is actually ".doc"
FileFormatInfo info = FileFormatUtil.detectFileFormat(docStream);
// Retrieve the LoadFormat of the document.
int loadFormat = info.getLoadFormat();
Document doc = new Document(getMyDir() + "Document.doc");
// This property will return the full path and file name where the document was loaded from.
String originalFilePath = doc.getOriginalFileName();
// Let's get just the file name from the full path.
String originalFileName = new File(originalFilePath).getName();
// This is the original LoadFormat of the document.
int loadFormat = doc.getOriginalLoadFormat();