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

相关推荐
BullSmall17 分钟前
Tomcat11证书配置全指南
java·运维·tomcat
永不停歇的蜗牛19 分钟前
K8S之创建cm指令create和 apply的区别
java·容器·kubernetes
爱学习的小可爱卢25 分钟前
JavaEE进阶——SpringBoot统一功能处理全解析
java·spring boot·后端·java-ee
汤姆yu27 分钟前
基于springboot的二手物品交易系统的设计与实现
java·spring boot·后端
中国胖子风清扬37 分钟前
Spring AI Alibaba + Ollama 实战:基于本地 Qwen3 的 Spring Boot 大模型应用
java·人工智能·spring boot·后端·spring·spring cloud·ai
foundbug9991 小时前
Modbus协议C语言实现(易于移植版本)
java·c语言·前端
听风吟丶1 小时前
Java 反射机制深度解析:从原理到实战应用与性能优化
java·开发语言·性能优化
一缕猫毛1 小时前
Flink demo代码
java·大数据·flink
小安同学iter1 小时前
天机学堂-优惠券功能-day09(七)
java·spring cloud·微服务·jenkins·优惠券·天机学堂