
jacob-1.18工具包已提供。
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
jacob-1.18 包含了 jacob-1.18-x64.dll 和 jacob-1.18-x86.dll 这两个动态链接库,经过验证确认能够正常运行。以下是使用该库进行文档转换为 PDF 的具体操作方法:
```java
package com.pdf.doctopdf.pdf;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import java.io.File;
public class TestJacob {
public static void main(String args[]) {
ActiveXComponent app = null;
String wordFile = C:\\Users\\admin\\Desktop\\jar\\年会系统优化_20210820_V0.2.docx;
String pdfFile = C:\\Users\\admin\\Desktop\\jar\\测试pdf.pdf;
System.out.println(转换过程开始...); // 记录开始时间
long start = System.currentTimeMillis();
try {
// 初始化 Word 应用程序
app = new ActiveXComponent(Word.Application);
// 获取 Word 中所有打开的文档对象
Dispatch documents = app.getProperty(Documents).toDispatch();
System.out.println(尝试打开文件: + wordFile);
// 打开指定的 Word 文档
Dispatch document = Dispatch.call(documents, Open, wordFile, false, true).toDispatch();
// 检查目标 PDF 文件是否存在,如果存在则删除以避免冲突
File target = new File(pdfFile);
if (target.exists()) {
target.delete();
}
System.out.println(将文档另存为: + pdfFile);
// 将文档另存为 PDF 格式,指定宏值 17 表示 PDF 格式保存。这里使用了宏值来控制保存格式。
Dispatch savedocument = Dispatch.
全部评论 (0)


