WordToPDF2.java

用Java将Word转PDF

本例子测试了spire.doc.free-3.9.0.jar的包

html 复制代码
		<dependency>
			<groupId> e-iceblue </groupId>
			<artifactId>spire.doc.free</artifactId>
			<version>3.9.0</version>
		</dependency>
package word;

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

/**
 * spire.doc-3.4.3.jar
 * Java-itext-5.0.4.jar


<!--
maven库访问不了
https://mvnrepository.com/artifact/e-iceblue/spire.doc 


e-iceblue库才能访问
https://repo.e-iceblue.cn/repository/maven-public
https://repo.e-iceblue.cn/#browse/browse:maven-public
https://repo.e-iceblue.cn/#browse/browse:maven-public:e-iceblue%2Fspire.doc
https://repo.e-iceblue.cn/repository/maven-public/e-iceblue/spire.doc/5.4.10/spire.doc-5.4.10.jar
-->
<dependency>
    <groupId>e-iceblue</groupId>
    <artifactId>spire.doc</artifactId>
    <version>5.4.10</version>
</dependency>


<!-- https://mvnrepository.com/artifact/com.lowagie/itext -->
<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>4.2.0</version>
</dependency>


 * 
 *
 * @author ZengWenFeng
 * @date 2023.08.15
 */
public class WordToPDF2
{
	public static void test3()
	{
		//实例化Document类的对象
		Document doc = new Document();

		//加载Word
		doc.loadFromFile("d:\\ChatGPT.docx");

		//保存为PDF格式
		doc.saveToFile("d:\\ChatGPT_temp.pdf", FileFormat.PDF);

		
		//Evaluation Warning: The document was created with Spire.Doc for JAVA.
		
		/*
		<dependency>
			<groupId> e-iceblue </groupId>
			<artifactId>spire.doc.free</artifactId>
			<version>2.6.3</version>
		</dependency>
		
		<dependency>
			<groupId> e-iceblue </groupId>
			<artifactId>spire.doc.free</artifactId>
			<version>3.9.0</version>
		</dependency>
		
		<dependency>
			<groupId> e-iceblue </groupId>
			<artifactId>spire.doc.free</artifactId>
			<version>4.3.0</version>
		</dependency>
		
		<dependency>
			<groupId> e-iceblue </groupId>
			<artifactId>spire.doc.free</artifactId>
			<version>4.4.1</version>
		</dependency>

		<dependency>
			<groupId> e-iceblue </groupId>
			<artifactId>spire.doc.free</artifactId>
			<version>5.1.0</version>
		</dependency>
		 */
	}
	
	public static void main(String[] args)
	{
		long time1 = System.currentTimeMillis();
		
		test3();
		
		//
		long time2 = System.currentTimeMillis();
		
		//
		System.out.println("Word to PDF completed!time : " + (time2 - time1));
	}
}

遇到问题,1)正式包下载不下载,2)正式包有水印,3)文档格式错误

分别处理:

spire.doc.jar_spencer_tseng的博客-CSDN博客

Evaluation Warning: The document was created with Spire.Doc for JAVA._spencer_tseng的博客-CSDN博客

org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type pa_spencer_tseng的博客-CSDN博客

linux

yum install libgcc -y

yum install libgcc_s.so.1

相关推荐
Good Note7 分钟前
Golang的静态强类型、编译型、并发型
java·数据库·redis·后端·mysql·面试·golang
我就是我35243 分钟前
记录一次SpringMVC的406错误
java·后端·springmvc
向哆哆1 小时前
Java应用程序的跨平台性能优化研究
java·开发语言·性能优化
ekkcole1 小时前
windows使用命令解压jar包,替换里面的文件。并重新打包成jar包,解决Failed to get nested archive for entry
java·windows·jar
handsomestWei2 小时前
java实现多图合成mp4和视频附件下载
java·开发语言·音视频·wutool·图片合成视频·视频附件下载
全栈若城2 小时前
03 Python字符串与基础操作详解
java·开发语言·python
伯牙碎琴2 小时前
二、Spring Framework基础:IoC(控制反转)和DI(依赖注入)
java·spring·log4j
菲力蒲LY2 小时前
输入搜索、分组展示选项、下拉选取,全局跳转页,el-select 实现 —— 后端数据处理代码,抛砖引玉展思路
java·前端·mybatis
南宫生2 小时前
力扣每日一题【算法学习day.130】
java·学习·算法·leetcode
!!!5253 小时前
Java实现斗地主-做牌以及对牌排序
java·算法