maven依赖
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
<version>1.0.4</version>
</dependency>
java 代码实现
/**
* PdfConverter 转PDF
* @param sfileName
* @param toFileName
* @return
*/
public static boolean wordToPDF(String sfileName, String toFileName){
OutputStream out = null;
try {
XWPFDocument document=new XWPFDocument(new FileInputStream(new File(sfileName)));
//
File outFile = new File(toFileName);
outFile.getParentFile().mkdirs();
out = new FileOutputStream(outFile);
//gb2312
PdfOptions options= PdfOptions.create();
PdfConverter.getInstance().convert(document,out,options);
}catch (FileNotFoundException e){
LoggerUtil.error(PrintOpreateWord.class,e.getMessage(),e);
return false;
} catch (IOException e) {
LoggerUtil.error(PrintOpreateWord.class,e.getMessage(),e);
return false;
} finally {
if(out != null){
try {
out.close();
} catch (IOException e) {
LoggerUtil.error(PrintOpreateWord.class,e.getMessage(),e);
}
}
}
return true;
}
问题
在本地运行正常,但是到生产环境字体显示不出来。。。
解决办法
字体安装:
这里就把window上的字体打包,选择中文字体就行,上传到Ubuntu系统, 安装好就成。
window系统中的字体路径: C:\Windows\Fonts 下
找到字体库路径
/usr/share/fonts
目录下,在其中建立了一个win目录,用于存放上传的中文字体,
再执行命令:
fc-cache -fv
将字体刷到字体缓存中。然后重启下应用