The 17.4.0 version of Aspose.Words is unable open many Word documents based on one of out TechPubs’ Word templates.
However, an older version of Aspose.Words (11.1.0) will open any document based on this template. We need to use the newer version of Aspose due to its better handling of Visio diagrams.
Please advise. We can provide a sample, if that would help. Thanks!
Thanks for your inquiry. We will appreciate it if you please share your problematic Word templates as ZIP file along with your sample code to replicate issue at our end. We will look into the issue and will guide you accordingly.
I am attaching two Word .docm files. Both are able to be opened by Aspose.Words 11.1.0 but only one can be opened by Aspose 17.4.0. I have many more examples of each if you need them.
Fetch-n-Fill_works_Aspose.docm - works in both Aspose versions
Fetch-and-Fill_v12_updated.docm can only be opened by the older version
In our code, we try to open the Word doc with the newer version of Aspose. If it throws an Exception, we call out to en executable JAR that encapsulates the older version of Aspose.
void convertDocumentToHtml(EhddCommand ehddCommand, String pathToDocument, String documentOutputPath) {
setAsposeLicense()
Document document
try {
document = createDocumentFromPath(ehddCommand, pathToDocument)
} catch(Exception e) { //If the initial load of the Word doc fails, use the failover JAR file
triggerFailoverProcess(pathToDocument)
document = createDocumentFromPath(ehddCommand, pathToDocument)
}
document.save("${documentOutputPath}.html", SaveFormat.HTML);
}
private Document createDocumentFromPath(EhddCommand ehddCommand, String pathToDocument) {
Document document = new Document(pathToDocument)
document.acceptAllRevisions()
document.removeMacros()
return document
}
private void triggerFailoverProcess(String pathToDocument) {
GString shellCommand = assembleCommandObject(pathToDocument)
Process process = shellCommand.execute()
StringBuffer output = new StringBuffer()
StringBuffer error = new StringBuffer()
process.waitForProcessOutput(output, error)
if( ! output.toString().startsWith("success")) {
throw new EhddValidationException(error.toString())
}
}
This older version then opens the Word doc, removes macros and revisions, and writes the file back where the main application can finish the processing.
class EhddConverterService {
void convertWordDoc(String pathToDocument) {
log.info(SplunkLogUtils.toSplunkString([appEvent: "convertWordDoc"]))
setAsposeLicense()
Document document = createDocumentFromPath(pathToDocument)
log.info(SplunkLogUtils.toSplunkString([appEvent: "createDocumentFromPath", documentOutputPath: pathToDocument]))
int saveFormat = parseSaveFormatFromExtension(pathToDocument)
document.save(pathToDocument, saveFormat);
log.info(SplunkLogUtils.toSplunkString([appEvent: "save document"]))
}
private Document createDocumentFromPath(String pathToDocument) {
Document document = new Document(pathToDocument)
document.acceptAllRevisions()
document.removeMacros()
return document
}
private int parseSaveFormatFromExtension(String pathToDocument) {
String extension = pathToDocument.drop(pathToDocument.lastIndexOf('.') + 1)
return getSaveFormat(extension)
}
private int getSaveFormat(String extension) {
switch (extension.toLowerCase()) {
case 'docx': return SaveFormat.DOCX
case 'docm': return SaveFormat.DOCM
case 'doc': return SaveFormat.DOC
case 'dot': return SaveFormat.DOT
case 'dotm': return SaveFormat.DOTM
case 'dotx': return SaveFormat.DOTX
case 'rtf': return SaveFormat.RTF
default: return SaveFormat.DOCX
}
}
private void setAsposeLicense() {
def licenseStream = this.class.classLoader.getResourceAsStream('resources/Aspose.Total.Java.lic')
License license = new License()
license.setLicense(licenseStream)
}
Thanks for sharing the source documents. We have tested the scenario and noticed the reported issue. We have logged a regression ticket WORDSNET-15883 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.