Aspose生成pdf文档,linux乱码解决

/**
	* @Description Word转PDF
	* @param inPath 源文件(Word)
	* @param outPath 目标文件(PDF)
	* @param watermark 水印字符(为空则不加)
	* @author  han
	* @date 2021年3月26日 上午10:46:00
	 */
	public synchronized static void doc2pdf(String inPath, String outPath,String watermark) throws Exception {
        if (!getLicense()) {//验证去除头部的水印
            return;
        }
        FileOutputStream os =null;
        try {
            File file = new File(outPath); // 新建一个空白pdf文档
            log.info("getPathgetPathgetPath:::::::::::::" + file.getPath());

             os = new FileOutputStream(file);
//注意Linux环境需要这一行,不然乱码 ?
            FontSettings.setFontsFolder("/usr/share/fonts",true);
            Document doc = new Document(inPath); // Address是将要被转化的word文档
            if(StringUtils.isNotEmpty(watermark)) {
            	insertWatermarkText(doc,watermark);
            }
            log.info("getPathgetPathgetPath2222:::::::::::::" + file.getPath());
            doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,// EPUB, XPS, SWF 相互转换
        } catch (Exception e) {
            e.printStackTrace();
        	throw new RuntimeException("Word转PDF出错:"+e.getMessage());
        }finally {
            os.close();
		}
    }
//验证License 若不验证则转化出的pdf文档会有水印产生
	public static boolean getLicense() throws Exception {
        boolean result = false;
        try {
//            InputStream is = Test.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
            ClassPathResource classPathResource = new ClassPathResource("license.xml");
            InputStream is =classPathResource.getInputStream();
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        	throw new RuntimeException("验证License出错:"+e.getMessage());
        }
        return result;
    }

 特别注意:FontSettings.setFontsFolder("/usr/share/fonts",true);

1获取权限

        sudo chmod -R 755 /usr/share/fonts

2.将整个目录C:\Windows\Fonts\上传到linux下的/usr/shared/fonts/2.

        

        文件夹全部上传到/home/monitor/Fonts然后复制到目录

        sudo cp -r /home/monitor/Fonts/. /usr/share/fonts

3.安装ttmkfdir

        sudo yum -y install ttmkfdir

4.执行ttmkfdir命令

        ttmkfdir -e /usr/share/X11/fonts/encodings/encoding.dir

5刷新内存中的字体缓存.

        fc-cache

6.查看fc-list :lang=zh     

不需要重启。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值