aspose-word的简单使用以及转pdf线上乱码

2022-07-28,,,,

aspose-word的简单使用以及转pdf线上乱码

  • 1. 迅雷云盘下载jar包
  • 2. SpringBoot添加外包
  • 3. 简单Demo
  • 4. Linux添加字体

1. 迅雷云盘下载jar包

链接:https://pan.xunlei.com/s/VMLvprrCNBQWaUekE7zKAzkSA1
提取码:TiQa

2. SpringBoot添加外包

<dependency>
	<groupId>com.aspose</groupId>
	<artifactId>aspose-words</artifactId>
	<version>19.5</version>
	<scope>system</scope>
	<systemPath>${project.basedir}/src/main/resources/lib/aspose-words-19.5jdk.jar</systemPath>
</dependency>

<!-- 线上打包运行出错 注意这里 -->
<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<mainClass>com.tj.WebApplication</mainClass>
		<executable>true</executable>
		<!-- 允许导入外包 -->
		<includeSystemScope>true</includeSystemScope>
	</configuration>
</plugin>

3. 简单Demo

    // 版本一
    public void generation() throws Exception {
        // 你的模板位置
        Document doc = new Document("E:\\tmp\\template\\report.docx");
        // 实体类 和模板对应  <<[s.getNo()]>>   
        TjStoreModel tjStore = new TjStoreModel();
        tjStore.setNo("99999999999");
        tjStore.setCreateTime(new Date());
        ReportingEngine engine = new ReportingEngine();
        engine.buildReport(doc, tjStore, "s");
        doc.save("E:\\tmp\\template\\word.pdf");
    }

        // 版本二
        // 加载模板
        Document doc = new Document("E:\\tmp\\template\\report.docx");
        ReportingEngine engine = new ReportingEngine();
        Range range = doc.getRange();
        // 替换模板
        range.replace("no","1111111111",true,false);
        range.replace("name","Jack魏",true,false);
        range.replace("phone","18899996666",true,false);
        doc.save("E:\\tmp\\template\\word.pdf");

4. Linux添加字体

C:\Windows\Fonts 这下面找到你想要的字体
根据Word里面查看需要的字体

然后上传到Linux服务器/usr/share/fonts/下面

# 查看Linux目前的所有字体
fc-list

# 查看Linux目前的所有中文字体
fc-list :lang=zh

# 安装字体
fc-cache -fv

一般可能不会有效, 记得先重启一下项目!!!!
如果重启项目还是无效, 再试一下重启服务器

本文地址:https://blog.csdn.net/WeiHao0240/article/details/109649394

《aspose-word的简单使用以及转pdf线上乱码.doc》

下载本文的Word格式文档,以方便收藏与打印。