在Linux服务器上进行word转pdf(解决无中文字体问题) 您所在的位置:网站首页 崩坏3游戏视频解说全集 在Linux服务器上进行word转pdf(解决无中文字体问题)

在Linux服务器上进行word转pdf(解决无中文字体问题)

2024-02-06 09:45| 来源: 网络整理| 查看: 265

首先要解决的是linux上没有中文字体的问题,这使得转换的pdf中字体有乱码。 其次要选择合适依赖文件,我使用的是免费开源的com.spire.doc.Document。 注意创建好相关目录:字体安装目录、pdf文件存储目录。

1. 上传中文字体

windows中文字体存放在:C:\Windows\Fonts

然后将字体打包上传到 /usr/share/fonts/chinese 下 (没有就创建目录) ,依次执行一下命令:

chmod 775 /usr/share/fonts/chinesecd /usr/share/fonts/chinesesudo mkfontscalesudo mkfontdirsudo fc-cache -fv 2. 创建pdf文件存储目录 mkdir /weaver/ecology/***/targetFilePath 3. 代码 /** * 将word转化成pdf并返回流 * * @param inputStream * @return * @throws Exception */ private FileInputStream convertPdf(InputStream inputStream) { FileInputStream fileInputStream = null; BaseBean baseBean = new BaseBean(); try { com.spire.doc.Document doc = new com.spire.doc.Document(); doc.loadFromStream(inputStream, FileFormat.Docx); String filePath = GCONST.getRootPath() + "filesystem" + File.separatorChar + "targetFilePath" + File.separatorChar + "target.pdf"; baseBean.writeLog(filePath); //保存为PDF格式 doc.saveToFile(filePath, FileFormat.PDF); fileInputStream = new FileInputStream(filePath); return fileInputStream; } catch (Exception e) { baseBean.writeLog(e); } return fileInputStream; }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有