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

相关推荐
Hygge-star5 分钟前
【数据结构】二分查找-LeftRightmost
java·数据结构·算法
张扬飞舞10 分钟前
IntelliJ IDEA打开项目后,目录和文件都不显示,只显示pom.xml,怎样可以再显示出来?
xml·java·intellij-idea
oneDay++10 分钟前
# IntelliJ IDEA企业版集成AI插件「通义灵码」全流程详解:从安装到实战
java·经验分享·学习·intellij-idea·学习方法
长勺18 分钟前
Spring Security vs Shiro vs Sa-Token
java·后端·spring
为美好的生活献上中指1 小时前
java每日精进 5.14【参数校验】
java·开发语言·spring boot·tomcat
qq_12498707531 小时前
原生小程序+springboot+vue+协同过滤算法的音乐推荐系统(源码+论文+讲解+安装+部署+调试)
java·spring boot·后端·小程序·毕业设计·课程设计·协同过滤
曾昭武1 小时前
IDEA怎么汉化&idea中文改回英文版
java·intellij-idea·idea汉化·idea怎么汉化·idea转回英文
信徒_2 小时前
SpringBoot 自动装配流程
java·spring boot·后端
小薛博客3 小时前
4、前后端联调文生文、文生图事件
java·ai
愛~杦辷个訾4 小时前
芋道项目,商城模块数据表结构
java·sql·芋道·yudao-cloud·芋道商城