HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
try {
saveOptions.setShowPageBorder(false);
saveOptions.setPrettyFormat(true);
saveOptions.setExportEmbeddedCss(true);
saveOptions.setExportEmbeddedFonts(true);
saveOptions.setExportEmbeddedImages(true);
saveOptions.setExportEmbeddedSvg(true);
saveOptions.setWarningCallback(new IWarningCallback() {
@Override
public void warning(WarningInfo warningInfo) {
if (WarningType.FONT_EMBEDDING == warningInfo.getWarningType()
|| WarningType.FONT_SUBSTITUTION == warningInfo.getWarningType()) {
ConverterLogger.logInfo(getClass(), warningInfo.getDescription());
}
}
});
for (Field field : word.getRange().getFields()) {
if (FieldType.FIELD_HYPERLINK == field.getType()) {
((FieldHyperlink) field).setTarget("_blank");
}
}
saveOptions.setUpdateFields(false);
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath || throwable instanceof OutOfMemoryError) {
throw throwable;
} else {
throw new Exception("aspose_setting", throwable);
}
}
int htmlPageCount = 0;
try {
htmlPageCount = word.getPageCount();
viewerParam.put("htmlPageCount", htmlPageCount);
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath || throwable instanceof OutOfMemoryError) {
throw throwable;
} else {
throw new Exception("aspose_getPageCount", throwable);
}
}
String pageKey = "page-";
IConvertFile pageConvertFile = null;
OutputStream pageConvertStream = null;
for (int i = 1; i <= htmlPageCount; i++) {
try {
ConverterLogger.logDebug(getClass(), "文件-" + sourceFile.getFileName() + "-第" + i + "页转换HTML开始:\n"); //the no.page converts HTML to the beginning
saveOptions.setPageIndex(i - 1);
saveOptions.setPageCount(1);
try {
pageConvertFile = sourceFile.newConvertFile(pageKey + i + "-svg");
pageConvertStream = pageConvertFile.getOutputStream();
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath || throwable instanceof OutOfMemoryError) {
throw throwable;
} else {
throw new Exception("createConvertFile", throwable);
}
}
try {
word.save(pageConvertStream, saveOptions);
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath || throwable instanceof OutOfMemoryError) {
throw throwable;
} else {
throw new Exception("aspose_convert", throwable);
}
}
ConverterLogger.logDebug(getClass(), "文件-" + sourceFile.getFileName() + "-第" + i + "页转换HTML结束:\n"); //The no. page converts HTML to the end
} catch (Throwable throwable) {
throw throwable;
} finally {
if (pageConvertStream != null) {
try {
pageConvertStream.close();
} catch (Exception e) {
//
}
}
System.gc();
}
}