word转PDF不能显示中文字体问题

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

将字体刷到字体缓存中。然后重启下应用

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值