gpt4 book ai didi

java - ObfuscatedFontPart.deleteEmbeddedFontTempFiles 中的 docx4j NullPointerException

转载 作者:行者123 更新时间:2023-11-29 04:55:49 27 4
gpt4 key购买 nike

我在我的软件中使用 docx4j 将 docx 文件转换为 html。我在基于 Windows 的系统中开发,我的产品是 AWS 中的 Ubuntu Linux 14.04。在 Windows 中一切正常,但在 Ubuntu 中,它抛出如下异常。

2015-11-19 07:33:36 ERROR AbstractExporter:108 - Exception exporting package java.lang.NullPointerException at org.docx4j.openpackaging.parts.WordprocessingML.ObfuscatedFontPart.deleteEmbeddedFontTempFiles(ObfuscatedFontPart.java:263) at org.docx4j.openpackaging.parts.WordprocessingML.FontTablePart.deleteEmbeddedFontTempFiles(FontTablePart.java:161) at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:91) at org.docx4j.Docx4J.toHTML(Docx4J.java:511) at com.testbudha.document.impl.WordDocumentExtractor.toHtml(WordDocumentExtractor.java:31) at com.testbudha.document.impl.DocXExtractor.getText(DocXExtractor.java:31) at com.testbudha.document.impl.DocumentServiceImpl.getFileText(DocumentServiceImpl.java:18) at com.testbudha.server.controller.StudentHomeController.getResumeText(StudentHomeController.java:120)

我知道这是一个字体相关的问题,我尝试安装

ttf-mscorefonts-installer

但它并没有改变任何东西我也尝试使用这个脚本安装 vista 字体。然后我也遇到了同样的异常

Vista fonts installer

protected String toHtml(WordprocessingMLPackage wordMLPackage, String path, HttpServletRequest request)
throws Docx4JException {
try {

HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
htmlSettings.setImageDirPath(path + "/_files");
htmlSettings.setImageTargetUri(request.getContextPath() + "/getfile/");
htmlSettings.setWmlPackage(wordMLPackage);

OutputStream os = new ByteArrayOutputStream();
Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
String outputHtml = ((ByteArrayOutputStream) os).toString().replaceAll("Â", "\n").replaceAll(" – ", "-")
.replaceAll("(?s)â€.\\s*", "").replaceAll("\\[(.*?)\\]","").replaceAll("#\\?", "")
.replaceAll("\\s*(?i)HYPERLINK\\s\\S\\s*(\"([^\"]*\")|'[^']*'|([^'\">\\s]+))+\"", "($1)")
.replaceAll("(\\([^)]*\\))\\s?(\\w+)", "$2$1");
return outputHtml;
} finally {
if (wordMLPackage.getMainDocumentPart().getFontTablePart() != null) {
wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
}
}

它正在抛出异常

Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);

最佳答案

https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/ObfuscatedFontPart.java#L263

tmpFontDir 似乎是 null,可能是因为 System.getProperty("user.home") 返回 null

所以在添加到类路径的 Docx4j.properties 文件中设置属性“docx4j.openpackaging.parts.WordprocessingML.ObfuscatedFontPart.tmpFontDir”。

关于java - ObfuscatedFontPart.deleteEmbeddedFontTempFiles 中的 docx4j NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33799424/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com