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

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.NullPointerException
at 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)

繁花如伊
浏览 158回答 1
1回答

猛跑小猪

因为它找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;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java