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

相关推荐
程序员吕洞宾4 分钟前
开源多维表格SmartTable V1.6.1:工作流画布,让自动化工作流配置更直观、更方便
java·开源·自动化
我登哥MVP9 分钟前
走进 Gang of Four 设计模式:访问者模式
java·设计模式·访问者模式·原型模式
雪碧聊技术12 分钟前
一文深入理解 Java 函数式编程思想
java·函数式编程
AIGS00116 分钟前
突破语义鸿沟:从向量空间JBoltAI看企业大脑构建逻辑
java·大数据·人工智能·人工智能ai大模型应用
琢磨先生David21 分钟前
OpenJDK 与 Oracle JDK 完整区别
java
倔强的石头10626 分钟前
企业智能设备运维管理系统:靠飞算 JavaAI,告别 Java 低效搬砖日常
java
深盾科技_Virbox37 分钟前
软件授权工具静默安装实践
java·运维·数据库·安全·软件需求
qq_452396231 小时前
第二篇:《Jenkins 从零搭建:安装、配置与第一个 Pipeline》
java·运维·jenkins
AI人工智能+电脑小能手1 小时前
【大白话说Java面试题 第172题】【07_Redis篇】第8题:`setnx` 做分布式锁存在的问题
java·redis·分布式锁·死锁·setnx
折哥的程序人生 · 物流技术专研1 小时前
Java 23 种设计模式:从踩坑到精通 | 番外:代理 vs 装饰器 —— Spring AOP 到底用了哪个?
java·代理模式·装饰器模式·java面试·java设计模式·springaop·从踩坑到精通