接上一篇,java将docx转pdf中文乱码,显示方框,是因为缺少字体

下面是如何安装字体
windows的字体在C:\Windows\Fonts下

linux的字体在./usr/share/fonts下,dejavu是默认的

创建 /usr/share/fonts/chinese 目录

 mkdir -p /usr/share/fonts/chinese

然后把 windows fonts 目录下的字体放入目录下

mv fonts/* /usr/share/fonts/chinese/

然后执行如下命令让字体生效
 

cd /usr/share/fonts/chinese

mkfontscale  (需安装yum install mkfontscale)

fc-cache -fv (需安装 yum install fontconfig)

source /etc/profile

搞定!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用Java和LibreOffice(UNO API)可以将docx文件换为pdf文件。下面是实现此操作的步骤: 1. 首先,需要安装LibreOffice软件并启动它。 2. 然后,使用Java代码连到LibreOffice的UNO API。 3. 下来,使用UNO API打开docx文件。 4. 然后,使用UNO API将docx文件换为pdf文件。 5. 最后,关闭docx文件和LibreOffice。 下面是一个简单的Java代码示例,演示如何使用LibreOffice(UNO API)将docx文件换为pdf文件: ```java import com.sun.star.beans.PropertyValue; import com.sun.star.frame.XComponentLoader; import com.sun.star.lang.XComponent; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.util.XCloseable; public class DocxToPdfConverter { public static void main(String[] args) { String inputFile = "input.docx"; String outputFile = "output.pdf"; XComponentContext context = null; XComponentLoader loader = null; XComponent document = null; try { // Connect to LibreOffice UNO API context = com.sun.star.comp.helper.Bootstrap.bootstrap(); loader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, context.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", context)); // Open docx file PropertyValue[] propertyValues = new PropertyValue[1]; propertyValues[0] = new PropertyValue(); propertyValues[0].Name = "Hidden"; propertyValues[0].Value = Boolean.TRUE; document = loader.loadComponentFromURL("file:///" + inputFile, "_blank", 0, propertyValues); // Convert docx to pdf PropertyValue[] convertProperties = new PropertyValue[2]; convertProperties[0] = new PropertyValue(); convertProperties[0].Name = "FilterName"; convertProperties[0].Value = "writer_pdf_Export"; convertProperties[1] = new PropertyValue(); convertProperties[1].Name = "Overwrite"; convertProperties[1].Value = Boolean.TRUE; ((com.sun.star.frame.XStorable) UnoRuntime.queryInterface(com.sun.star.frame.XStorable.class, document)).storeToURL("file:///" + outputFile, convertProperties); // Close docx file and LibreOffice ((XCloseable) UnoRuntime.queryInterface(XCloseable.class, document)).close(true); document.dispose(); context.getServiceManager().createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context).queryInterface(XComponent.class).dispose(); context.dispose(); } catch (Exception e) { e.printStackTrace(); } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱学习hahaha

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值