为了账号安全,请及时绑定邮箱和手机立即绑定

请问这么引入rtf文件为什么会报如下错误:

请问这么引入rtf文件为什么会报如下错误:

繁花如伊 2022-10-02 13:09:46
Document document = new Document(PageSize.A4);RtfWriter2 rtf = RtfWriter2.getInstance(document, new FileOutputStream("path"));document.open();BaseFont bfChinese = BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);rtf.importRtfDocument(new FileInputStream("oldPath"));document.add(new Paragraph("Hello World"));document.close();java.lang.NullPointerExceptionat com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.importSystemFonts(Unknown Source)at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.init(Unknown Source)at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.setParser(Unknown Source)at com.lowagie.text.rtf.parser.destinations.RtfDestinationMgr.addDestination(Unknown Source)at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordHandler.<init>(Unknown Source)at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMap.<init>(Unknown Source)at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMgr.<init>(Unknown Source)at com.lowagie.text.rtf.parser.RtfParser.init(Unknown Source)at com.lowagie.text.rtf.parser.RtfParser.importRtfDocument(Unknown Source)at com.lowagie.text.rtf.RtfWriter2.importRtfDocument(Unknown Source)at com.lowagie.text.rtf.RtfWriter2.importRtfDocument(Unknown Source)
查看完整描述

1 回答

?
猛跑小猪

TA贡献1858条经验 获得超8个赞

因为它找font只支持到windows vista,你要补充个windows7或8的条件在源码里,然后编译打包替换。
private Properties getEnvironmentVariables() throws Throwable {
Properties environmentVariables = new Properties();
String operatingSystem = System.getProperty("os.name").toLowerCase();
Runtime runtime = Runtime.getRuntime();
Process process = null;
if (operatingSystem.indexOf("windows 95") > -1
|| operatingSystem.indexOf("windows 98") > -1
|| operatingSystem.indexOf("me") > -1) {
process = runtime.exec("command.com /c set");
} else if ((operatingSystem.indexOf("nt") > -1)
|| (operatingSystem.indexOf("windows 2000") > -1)
|| (operatingSystem.indexOf("windows xp") > -1)
|| (operatingSystem.indexOf("windows 2003") > -1)
|| (operatingSystem.indexOf("windows 7") > -1)
|| (operatingSystem.indexOf("windows vista") > -1)) {
process = runtime.exec("cmd.exe /c set");
} else {
process = runtime.exec("env");
}
BufferedReader environmentStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
String inputLine = "";
int idx = -1;
while ((inputLine = environmentStream.readLine()) != null) {
idx = inputLine.indexOf('=');
environmentVariables.setProperty(inputLine.substring(0, idx),
inputLine.substring(idx + 1));
}
return environmentVariables;
}

查看完整回答
反对 回复 2022-10-06
  • 1 回答
  • 0 关注
  • 157 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号