Hi Guys,
I am getting an IllegalStateException when I try to convert the attached doc from docx to HTML.
Here is the stack trace:
[error] (run-main-0) java.lang.IllegalStateException: Unexpected table container.
java.lang.IllegalStateException: Unexpected table container.
at com.aspose.words.zzZ2L.zzL(Unknown Source)
at com.aspose.words.zzX.zzZ(Unknown Source)
at com.aspose.words.zzX.zzW(Unknown Source)
at com.aspose.words.zz5.zzU(Unknown Source)
at com.aspose.words.zzZ59.zzYQ(Unknown Source)
at com.aspose.words.zzBM.moveNext(Unknown Source)
at com.aspose.words.zzBS.zzZ(Unknown Source)
at com.aspose.words.zzBS.zzZ(Unknown Source)
at com.aspose.words.zzZRY.zzZ(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.aspose.words.Document.zzXL(Unknown Source)
at com.aspose.words.Document.zzbX(Unknown Source)
at com.aspose.words.zzZY0.zzZ(Unknown Source)
at com.aspose.words.zz0Q.zzZZj(Unknown Source)
at com.aspose.words.zz0Q.zzZZs(Unknown Source)
at com.aspose.words.zz0Q.zzZZx(Unknown Source)
at com.aspose.words.zzZWQ.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
Here is the conversion code (in Scala):
val options = new HtmlSaveOptions(SaveFormat.HTML)
options.setImagesFolder(imageDir.getPath)
options.setUseAntiAliasing(true)
options.setUseHighQualityRendering(true)
// Prevent scaling of images.
options.setScaleImageToShapeSize(false)
// Ensure the file names for images are sanitized.
options.setImageSavingCallback(FilenameSanitizingSavingCallback)
// Ensure external images are still linked.
options.setExportOriginalUrlForLinkedImages(true)
// Ensure lists are exported as / and tags.
options.setExportListLabels(ExportListLabels.BY_HTML_TAGS)
for {
// Load the document.
asposeDoc <- Try(new AsposeDocument(file.getAbsolutePath))
// Convert to HTML.
_ <- Try(asposeDoc.save(htmlFile.getAbsolutePath, options))
} yield {}
object FilenameSanitizingSavingCallback extends IImageSavingCallback {
/**
* Handle an image save callback. This will force the filename to be lowercase.
*
* @param imageSavingArgs Information about the image.
*/*
def imageSaving(imageSavingArgs: ImageSavingArgs): Unit = {
// Ensure file names are lowercase and do not contain invalid characters.
imageSavingArgs.setImageFileName(
imageSavingArgs.getImageFileName.toLowerCase.replaceAll("[^-a-z0-9_\/\.]", "")
)
}
}