说明
Jacob组件下载地址:[https://sourceforge.net/projects/jacob-project/]
使用
1、引入jacob.jar
2、maven配置打war包时,引用外部资源
<dependency>
<groupId>com.jacob</groupId>
<artifactId>jacob</artifactId>
<version>1.19</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jacob.jar</systemPath>
</dependency>
3、将jacob-1.19-x64.dll放在jdk目录中jre/bin目录下
代码
1、word转pdf
package com.lynn.springboot_demo.test;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import java.io.File;
import java.io.IOException;
/**
* @author cl
* @Date 2020/9/7 09:53
* word转pdf jacob方法
*/
public class WordToPdf {
static final int wdDoNotSaveChanges = 0;// 不保存待定的更改。
static final int wdFormatPDF = 17;// word转PDF 格式
public static void main(String[] args) throws IOException {
String source1 = "C:\\Users\\Administrator\\Desktop\\test.doc";
String target1 = "C:\\Users\\Administrator\\Desktop\\temp.pdf";
wordToPdf.word2pdf(source1, target1);
}
public static boolean word2pdf(String source, String target) {
System.out.println("Word转PDF开始启动...");
long start = System.currentTimeMillis