文章目录
[Aspose.PDF for Java --- PDF 转 Word 完整技术方案](#Aspose.PDF for Java — PDF 转 Word 完整技术方案)
[二、Maven 依赖配置](#二、Maven 依赖配置)
[三、License 授权配置](#三、License 授权配置)
[方案 A:永久授权(推荐生产环境)](#方案 A:永久授权(推荐生产环境))
[方案 B:按量计费 Metered License(适合初期低成本启动)](#方案 B:按量计费 Metered License(适合初期低成本启动))
[4.1 基础转换 Service](#4.1 基础转换 Service)
[4.2 转换参数优化(提升质量的关键配置)](#4.2 转换参数优化(提升质量的关键配置))
[4.3 与 SpringBoot Controller 集成](#4.3 与 SpringBoot Controller 集成)
[5.1 授权费用对比](#5.1 授权费用对比)
[5.2 对你的产品的成本估算](#5.2 对你的产品的成本估算)
方法一:使用破解的license.xml文件进行授权,同时通过代码移除生成文档中的水印
方法二:通过修改aspose-pdf的jar包,使用javassist修改ADocument类的两个方法(限制转换页数和水印)
2、破解代码Ctrl+C/V修改一下路径,直接运行,也可以直接丢给AI(让其自动完成)

前言
Aspose.PDF 是一个 Java 组件,旨在允许开发人员以编程方式即时创建简单或复杂的 PDF 文档。Aspose.PDF for Java 允许开发人员在 PDF 文档中插入表格、图形、图像、超链接、自定义字体等。此外,还可以压缩 PDF 文档。Aspose.PDF for Java 提供出色的安全功能以开发安全的 PDF 文档。而 Aspose.PDF for Java 最显著的特点是它支持通过 API 和从 XML 模板创建 PDF 文档。
提示:以下是本篇文章正文内容,下面案例可供参考
Aspose.PDF for Java --- PDF 转 Word 完整技术方案
一、方案概述
| 项目 | 说明 |
|---|---|
| 技术选型 | Aspose.PDF for Java(纯 Java,无需额外环境) |
| 最新版本 | 25.3+(截至 2025 年) |
| 转换质量 | ★★★★★ --- 排版还原度极高,支持表格、图片、复杂布局 |
| 中文支持 | ★★★★★ --- 完美支持中文、中英混排 |
| 集成难度 | ★★★★★ --- 纯 Java 依赖,与 SpringBoot 无缝集成 |
| 授权方式 | 永久授权 $1,199 起 / 按量计费(Metered License) |
二、Maven 依赖配置
Aspose 未将所有版本发布到 Maven 中央仓库,需手动添加其私有仓库。
pom.xml:
XML
<properties>
<aspose.pdf.version>25.3</aspose.pdf.version>
</properties>
<repositories>
<repository>
<id>aspose-repo</id>
<name>Aspose Java API Repository</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>${aspose.pdf.version}</version>
</dependency>
</dependencies>
三、License 授权配置
方案 A:永久授权(推荐生产环境)
购买后将 Aspose.PDF.lic 文件放入 src/main/resources/license/ 目录。
Java
@Component
public class AsposeLicenseConfig {
@PostConstruct
public void init() {
try {
License license = new License();
// 从 classpath 加载 license 文件
InputStream is = getClass()
.getClassLoader()
.getResourceAsStream("license/Aspose.PDF.lic");
if (is != null) {
license.setLicense(is);
log.info("Aspose.PDF License 加载成功");
} else {
log.warn("未找到 Aspose.PDF License 文件,将使用评估模式(有水印)");
}
} catch (Exception e) {
log.error("Aspose.PDF License 加载失败", e);
}
}
}
方案 B:按量计费 Metered License(适合初期低成本启动)
Java
@Component
public class AsposeMeteredLicenseConfig {
@PostConstruct
public void init() {
try {
Metered metered = new Metered();
// 使用你在 Aspose 官网申请的公钥和私钥
metered.setMeteredKey(
"你的公钥-public-key",
"你的私钥-private-key"
);
log.info("Aspose.PDF Metered License 加载成功");
} catch (Exception e) {
log.error("Metered License 加载失败", e);
}
}
}
💡 Metered License 优势:按实际转换量计费,初期用户量小时成本极低,随业务增长自动扩展,无需一次性投入。
四、核心转换代码
4.1 基础转换 Service
Java
@Service
@Slf4j
public class PdfToWordService {
/**
* PDF 转 Word(DOCX)
*
* @param pdfFilePath 输入 PDF 文件路径
* @param outputDir 输出目录
* @return 转换后的 DOCX 文件路径
*/
public String convertPdfToWord(String pdfFilePath, String outputDir) {
long startTime = System.currentTimeMillis();
try {
// 1. 加载 PDF 文档
Document pdfDocument = new Document(pdfFilePath);
// 2. 设置转换参数(优化转换质量)
DocSaveOptions saveOptions = new DocSaveOptions();
saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);
// 识别列表/表格结构(提升排版还原度)
saveOptions.setRecognizeListItems(true);
// 相对对齐优化
saveOptions.setRelativeHorizontalProximity(2.5f);
// 模式:增强排版还原
saveOptions.setMode(DocSaveOptions.RecognitionMode.TextBoxFlow);
// 3. 生成输出文件名
String fileName = FilenameUtils.getBaseName(pdfFilePath) + ".docx";
String outputPath = outputDir + File.separator + fileName;
// 4. 执行转换
pdfDocument.save(outputPath, saveOptions);
pdfDocument.close();
long cost = System.currentTimeMillis() - startTime;
log.info("PDF转Word完成,耗时: {}ms,文件: {}", cost, outputPath);
return outputPath;
} catch (Exception e) {
log.error("PDF转Word失败,文件: {}", pdfFilePath, e);
throw new RuntimeException("PDF转Word转换失败: " + e.getMessage());
}
}
}
4.2 转换参数优化(提升质量的关键配置)
Java
/**
* 根据不同 PDF 类型选择最优转换策略
*/
public String convertWithStrategy(String pdfFilePath, String outputDir, ConvertStrategy strategy) {
Document pdfDocument = new Document(pdfFilePath);
DocSaveOptions saveOptions = new DocSaveOptions();
saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);
switch (strategy) {
case HIGH_FIDELITY:
// 高保真模式:最大程度还原排版(适合复杂排版的 PDF)
saveOptions.setMode(DocSaveOptions.RecognitionMode.TextBoxFlow);
saveOptions.setRecognizeListItems(true);
saveOptions.setRelativeHorizontalProximity(2.5f);
break;
case TEXT_FOCUS:
// 文本优先模式:牺牲部分排版,提升文本提取准确度(适合扫描件)
saveOptions.setMode(DocSaveOptions.RecognitionMode.PureTextBox);
break;
case FAST:
// 快速模式:转换速度最快(适合简单 PDF)
saveOptions.setMode(DocSaveOptions.RecognitionMode.TextBoxFlow);
saveOptions.setRecognizeListItems(false);
break;
default:
saveOptions.setMode(DocSaveOptions.RecognitionMode.TextBoxFlow);
}
String outputPath = outputDir + File.separator
+ FilenameUtils.getBaseName(pdfFilePath) + ".docx";
pdfDocument.save(outputPath, saveOptions);
pdfDocument.close();
return outputPath;
}
public enum ConvertStrategy {
HIGH_FIDELITY, // 高保真(默认推荐)
TEXT_FOCUS, // 文本优先
FAST // 快速转换
}
4.3 与 SpringBoot Controller 集成
Java
@RestController
@RequestMapping("/api/convert")
@Slf4j
public class ConvertController {
@Autowired
private PdfToWordService pdfToWordService;
@Autowired
private FileStorageService fileStorageService;
/**
* PDF 转 Word 接口
*/
@PostMapping("/pdf-to-word")
public Result<ConvertResultVO> convertPdfToWord(
@RequestParam("file") MultipartFile file,
@RequestParam(value = "strategy", defaultValue = "HIGH_FIDELITY") ConvertStrategy strategy) {
// 1. 校验文件
if (file.isEmpty()) {
return Result.fail("文件不能为空");
}
String originalName = file.getOriginalFilename();
if (!originalName.toLowerCase().endsWith(".pdf")) {
return Result.fail("仅支持 PDF 格式文件");
}
// 2. 保存上传文件到临时目录
String pdfFilePath = fileStorageService.saveTempFile(file);
try {
// 3. 执行转换
String outputDir = fileStorageService.getTempOutputDir();
String docxFilePath = pdfToWordService.convertWithStrategy(
pdfFilePath, outputDir, strategy);
// 4. 获取文件大小信息
File pdfFile = new File(pdfFilePath);
File docxFile = new File(docxFilePath);
ConvertResultVO result = new ConvertResultVO();
result.setOutputFileName(FilenameUtils.getName(docxFilePath));
result.setOutputFileSize(docxFile.length());
result.setInputFileSize(pdfFile.length());
result.setOutputUrl("/files/download/" + FilenameUtils.getName(docxFilePath));
return Result.success(result);
} finally {
// 5. 清理临时 PDF 文件(转换结果保留 48 小时后自动清理)
fileStorageService.scheduleDelete(pdfFilePath, 48);
}
}
}
五、成本分析
5.1 授权费用对比
| 授权类型 | 费用 | 适用场景 |
|---|---|---|
| 评估版(免费) | 免费,但输出有水印 | 开发测试阶段 |
| Metered License(按量) | 约 $0.01-0.03/次转换 | 初期上线、用户量不确定时 |
| Developer 永久授权 | 1,199(一次性)+399/年续订 | 用户量大、长期运营 |
| Developer OEM | 3,597(一次性)+1,199/年续订 | 多部署点、SaaS 平台 |
5.2 对你的产品的成本估算
场景:非会员每日 3 次免费,假设 DAU = 1000
日转换量 ≈ 1000 × 3 = 3,000 次/天
月转换量 ≈ 90,000 次/月
Metered License 成本 ≈ 90,000 × $0.02 ≈ $1,800/月(约 ¥13,000/月)
永久授权成本 ≈ $1,199 + $399/年 ≈ ¥11,500 首年(无限次)
💡 建议 :当月转换量超过 60,000 次时,永久授权比按量计费更划算。
六、部署架构
┌─────────────┐ ┌──────────────────┐ ┌─────────────┐
│ 微信小程序 │────▶│ SpringBoot 后端 │────▶│ MinIO │
│ (文件上传) │ │ Aspose.PDF 转换 │ │ (文件存储) │
└─────────────┘ └──────────────────┘ └─────────────┘
│
┌──────┴──────┐
│ MySQL │
│ (记录/用户) │
└─────────────┘
优势:纯 Java 方案,无需额外部署 Python 或 LibreOffice 环境,运维简单。
七、注意事项
| 项目 | 说明 |
|---|---|
| 评估水印 | 未配置 License 时,转换结果会有 "Evaluation Only" 水印,上线前必须配置正式 License |
| JDK 版本 | Aspose.PDF 25.x 要求 JDK 8+,推荐 JDK 17 |
| 内存消耗 | 大 PDF 文件(>50MB)转换时内存占用较高,建议设置 JVM 参数 -Xmx512m,并限制上传文件大小 |
| 异步处理 | 转换耗时较长时(>5 秒),建议使用 @Async 异步执行,避免阻塞 HTTP 线程 |
| 文件清理 | 转换完成后,临时文件需定时清理(建议保留 48 小时) |
八、总结建议
| 阶段 | 授权方案 | 理由 |
|---|---|---|
| 开发/测试 | 评估版(免费) | 验证功能,有水印不影响开发 |
| MVP 上线 | Metered License(按量) | 用户量不确定,按实际用量付费,降低初期成本 |
| 用户量稳定后 | 购买 Developer 永久授权 | 月转换量 >6 万次时,永久授权更经济 |
Sources:
- Aspose.PDF for Java 官方安装文档
- Aspose.PDF License 配置教程
- Metered License 按量计费指南
- Aspose.PDF 定价页面
- PDF 转 DOCX 完整教程
来到重点部分,请看大屏幕!!!
license破解
方法一:使用破解的license.xml文件进行授权,同时通过代码移除生成文档中的水印
示例代码:
java
public class PDFHelper3 {
public static void main(String[] args) throws Exception {
ClassPathResource classPathResource = new ClassPathResource("license.xml");
//调用授权方法
InputStream is =classPathResource.getInputStream();
License license = new License();
license.setLicense(is);
pdf2doc("G:\\logs\\2022草稿3.pdf");
//modifyPDFJar();
}
//移除文字水印
public static boolean removeWatermark(File file) {
try {
XWPFDocument doc = new XWPFDocument(new FileInputStream(file));
// 段落
List<XWPFParagraph> paragraphs = doc.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
String text=paragraph.getText();
if("Evaluation Only. Created with Aspose.PDF. Copyright 2002-2021 Aspose Pty Ltd.".equals(text)){
List<XWPFRun> runs = paragraph.getRuns();
runs.forEach(e-> e.setText("",0));
}
}
FileOutputStream outStream = new FileOutputStream(file);
doc.write(outStream);
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
//pdf转doc
public static void pdf2doc(String pdfPath) {
long old = System.currentTimeMillis();
try {
//新建一个doc文档
String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".docx";
File file = new File(wordPath);
FileOutputStream os = new FileOutputStream(file);
//Address是将要被转化的word文档
Document doc = new Document(pdfPath);
//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
doc.save(os, SaveFormat.DocX);
os.close();
//去除水印
removeWatermark(new File(wordPath));
//转化用时
long now = System.currentTimeMillis();
System.out.println("Pdf 转 Word 共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
System.out.println("Pdf 转 Word 失败...");
e.printStackTrace();
}
}
//pdf转excel
public static void pdf2Excel(String pdfPath) {
long old = System.currentTimeMillis();
try {
//新建一个excel文档
String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".xls";
File file = new File(wordPath);
FileOutputStream os = new FileOutputStream(file);
//Address是将要被转化的word文档
Document doc = new Document(pdfPath);
//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
doc.save(os, SaveFormat.Excel);
os.close();
//去除水印
removeWatermark(new File(wordPath));
//转化用时
long now = System.currentTimeMillis();
System.out.println("Pdf 转 excel 共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
System.out.println("Pdf 转 excel 失败...");
e.printStackTrace();
}
}
}
license.xml:
XML
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>
sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=
</Signature>
</License>
pom.xml
XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.youfa</groupId>
<artifactId>pdfForWord</artifactId>
<version>1.0.0</version>
<name>pdfForWord</name>
<description>pdfForWord</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.3.7.RELEASE</spring-boot.version>
</properties>
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 使用本地aspose-pdf jar包 -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>21.11</version>
</dependency>
<!-- poi-ooxml是poi的升级版本-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.28.0-GA</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
<configuration>
<mainClass>com.youfa.pdfforword.PdfForWordApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
-
PDFHelper3.java :
-
使用 license.setLicense(is) 加载license.xml授权文件
-
实现了PDF转Word和Excel的功能
-
通过 removeWatermark 方法手动移除生成文档中的水印
-
注释掉了 modifyPDFJar() 方法,说明可能曾经考虑过jar包破解方式
-
-
license.xml :
-
包含Aspose.Total for Java和Aspose.Words for Java的授权信息
-
授权到期时间为2099年12月31日
-
包含序列号和签名
-
-
pom.xml :
-
依赖了aspose-pdf 21.11版本
-
包含了javassist依赖(可能用于jar包破解,但当前未使用)
-
配置了Aspose的Maven仓库
-
方法二:通过修改aspose-pdf的jar包,使用javassist修改ADocument类的两个方法(限制转换页数和水印)
jar包破解
1、pom文件
XML
分别复制进pom文件,记得配置maven的中央仓库在settings.xml中
配置单独的仓库地址
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
相关依赖
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aspose/aspose-pdf -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>21.8</version>
</dependency>
2、破解代码
Ctrl+C/V修改一下路径,直接运行,也可以直接丢给AI(让其自动完成)
java
import cn.comingnet.app.bean.JumpInfo;
import cn.comingnet.app.bean.SchemeDto;
import cn.comingnet.common.util.HttpClientUtils;
import cn.comingnet.common.util.Jsons;
import cn.comingnet.common.util.StringUtil;
import cn.comingnet.front.constants.BaseConst;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import com.aspose.pdf.internal.imaging.internal.Exceptions.IO.FileNotFoundException;
import javassist.*;
import org.apache.batik.i18n.LocaleGroup;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.helpers.LogLog;
import org.junit.Test;
import java.io.*;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
public class Demo {
public static void main(String[] args) throws Exception {
//找到自己的maven仓库这个jar包对应的路径,替换掉,别的不需要动
String jarPath = "E:\\maven\\mvnRepository\\com\\aspose\\aspose-pdf\\21.8\\aspose-pdf-21.8.jar";
crack(jarPath);
}
private static void crack(String jarName) {
try {
ClassPool.getDefault().insertClassPath(jarName);
CtClass ctClass = ClassPool.getDefault().getCtClass("com.aspose.pdf.ADocument");
CtMethod[] declaredMethods = ctClass.getDeclaredMethods();
int num = 0;
for (int i = 0; i < declaredMethods.length; i++) {
if (num == 2) {
break;
}
CtMethod method = declaredMethods[i];
CtClass[] ps = method.getParameterTypes();
if (ps.length == 2
&& method.getName().equals("lI")
&& ps[0].getName().equals("com.aspose.pdf.ADocument")
&& ps[1].getName().equals("int")) {
// 最多只能转换4页 处理
System.out.println(method.getReturnType());
System.out.println(ps[1].getName());
method.setBody("{return false;}");
num = 1;
}
if (ps.length == 0 && method.getName().equals("lt")) {
// 水印处理
method.setBody("{return true;}");
num = 2;
}
}
File file=new File(jarName);
ctClass.writeFile(file.getParent());
disposeJar(jarName, file.getParent()+"/com/aspose/pdf/ADocument.class");
} catch(NotFoundException e){
e.printStackTrace();
} catch(CannotCompileException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void disposeJar(String jarName, String replaceFile) {
List<String> deletes = new ArrayList<>();
deletes.add("META-INF/37E3C32D.SF");
deletes.add("META-INF/37E3C32D.RSA");
File oriFile = new File(jarName);
if (!oriFile.exists()) {
System.out.println("######Not Find File:" + jarName);
return;
}
//将文件名命名成备份文件
String bakJarName = jarName.substring(0, jarName.length() - 3) + "cracked.jar";
// File bakFile=new File(bakJarName);
try {
//创建文件(根据备份文件并删除部分)
JarFile jarFile = new JarFile(jarName);
JarOutputStream jos = new JarOutputStream(new FileOutputStream(bakJarName));
Enumeration entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
if (!deletes.contains(entry.getName())) {
if (entry.getName().equals("com/aspose/pdf/ADocument.class")) {
System.out.println("Replace:-------" + entry.getName());
JarEntry jarEntry = new JarEntry(entry.getName());
jos.putNextEntry(jarEntry);
FileInputStream fin = new FileInputStream(replaceFile);
byte[] bytes = readStream(fin);
jos.write(bytes, 0, bytes.length);
} else {
jos.putNextEntry(entry);
byte[] bytes = readStream(jarFile.getInputStream(entry));
jos.write(bytes, 0, bytes.length);
}
} else {
System.out.println("Delete:-------" + entry.getName());
}
}
jos.flush();
jos.close();
jarFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
private static byte[] readStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = inStream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
}
outSteam.close();
inStream.close();
return outSteam.toByteArray();
}
}
运行上面的主方法,破解成功后,会再同级文件夹下生成一个aspose-pdf-21.11.cracked.jar包,用这个包替换原来的aspose-pdf-21.11.jar包即可。
提示:想要jar包可联系博主,jar包只能私发
3、代码实现示例
java
public class Demo {
//放入一个pdf的路径
public static void main(String[] args) throws IOException {
pdf2doc("D:\\浏览器下载\\edg\\1_20221130145105.pdf");
}
//pdf转doc
public static void pdf2doc(String pdfPath) {
long old = System.currentTimeMillis();
try {
//新建一个word文档
String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".docx";
FileOutputStream os = new FileOutputStream(wordPath);
//doc是将要被转化的word文档
Document doc = new Document(pdfPath);
//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
doc.save(os, SaveFormat.DocX);
os.close();
//转化用时
long now = System.currentTimeMillis();
System.out.println("Pdf 转 Word 共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
System.out.println("Pdf 转 Word 失败...");
e.printStackTrace();
}
}
}
OK!!!
总结
方法一:采用了license.xml授权 + 手动移除水印的方式。这种方式虽然配置简单,但可能存在授权有效性的风险。
-
优势 :使用license.xml授权方式更简单,不需要修改jar包
-
局限性 :
-
生成的文档仍会有水印,需要通过代码手动移除
-
license.xml的有效性可能会受到Aspose官方的验证
-
方法二:需要修改jar包,操作较复杂
- 优势 :直接修改jar包中的类方法,从根本上禁用水印和页数限制
博主提醒:条件允许,还是要支持正版,不能使用第三方工具进行破解!!!
