Code:
List<DocReadFilePro> docReadFilesPros = new ArrayList(); WordPropsUtil.setProperty(ParamKeys.WORD_IMAGE_RESOLUTION, wordImageResolution);
HtmlSaveOptions htmlSaveOptions = HtmlSaveOptionsBuilder.build(documentWrap, this.getImageSaveDir(), this.getOleSaveDir(), null);
htmlSaveOptions.setImageSavingCallback(new HtmlSaveCustomIImageHDSavingCallback(this.getImageSaveDir(), this.getOleSaveDir(), docReadFilesPros, HtmlSaveCustomIImageHDSavingCallback.LocalStorageImageHdEnum.STORAGE_BYTEARR));
//word转换成html格式
String documentStr = dstDoc.getDocument().toString(htmlSaveOptions);
StackTrace :
[17] Attached template path is empty, styles were not updated. (code : 1)
[3] Office math is not supported in Html format and will be converted to shape. (Code: 65536)
Caused by: java.lang.IllegalArgumentException: Expected a value between 0 and 3291.
Parameter name: index
at com.aspose.words . internal .ZZZjP . ZZYkb (Unknown source)
at com.aspose _ vords. internal. zzxsQ. zzYSu (Unknown source)
at com.aspose.words.internal.zzXsQ.get (Unknown Source)
at com aspose. words . internal.zzxon. ZZR8 (Unknown source)
at com.aspose .words . internal- zzWxI. ZzYkb …
@JLong_Chen
Cause
The error you are encountering is related to the handling of Office Math in the document you are trying to convert to HTML. The message indicates that Office Math is not supported in HTML format and will be converted to shapes, which may lead to an IllegalArgumentException
due to an unexpected index value.
Solution
To resolve this issue, follow these steps:
-
Check Document Content: Ensure that the document does not contain unsupported elements or excessive complexity, particularly with Office Math content.
-
Update Aspose.Words: Verify that you are using the latest version of the Aspose.Words library, as updates often include bug fixes and improved support for various features.
-
Handle Math Content: If your document contains Office Math, convert it to a supported format before rendering to HTML. Use the HtmlSaveOptions
to specify how to handle such content.
-
Adjust Index Handling: Review your code to ensure that any index values used are within the expected range. The error message indicates that an index value is out of bounds, so check any loops or array accesses.
Code Example
Here’s a basic example of how to set up HtmlSaveOptions
while handling potential math content:
import com.aspose.words.Document;
import com.aspose.words.HtmlSaveOptions;
public class DocumentConverter {
public static void main(String[] args) {
try {
Document doc = new Document("path/to/your/document.docx");
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setExportMathAsText(true); // Handle math content
doc.save("path/to/output/document.html", saveOptions);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Next Steps
- Implement the suggested changes and run your conversion again.
- If the issue persists, simplify the document by removing complex elements and test again.
- If you continue to face challenges, reach out to Aspose support with specific details about the issue.
Please let me know if you need further assistance!
HtmlSaveOptions 没有 setExportMathAsText() 这个方法
@JLong_Chen 此选项为 saveOptions.setOfficeMathOutputMode(HtmlOfficeMathOutputMode.TEXT);
。 但是,如果该选项无法解决您的问题,请提供导致问题的文件。
saveOptions.setOfficeMathOutputMode(HtmlOfficeMathOutputMode.TEXT);
可以输出文字,但是根号无法输出;
本地可以输出图片,但是服务器( Kylin Linux )失败:Office math is not supported in Html format and will be converted to shape. (Code: 65536)
简单附件:
根号解析.docx (10.3 KB)
@JLong_Chen 您还在遇到 "非法参数异常 "吗? 能否请您提供正在使用的 docker 文件以及安装的 Java 版本?警告Office math is not supported in Html format and will be converted to shape.
是预料之中的,在转换为 Html 时,OfficeMath 对象变成了 Shape 对象,其中包含图像。