Aspose docx 转 pdf
jar 包下载
https://releases.aspose.com/java/repo/com/aspose/aspose-words/21.11/aspose-words-21.11-jdk17.jar
参考文档
https://blog.aspose.com/words/convert-word-doc-docx-to-pdf-in-java-programmatically/#word-document
许可证购买(不买许可证,转换的文件有水印,且功能有限制)
https://purchase.aspose.com/buy
破解
第一步:下载jar
第二步:jd-gui.exe 反编译,保存代码
第三步:创建一个测试maven项目
第四步:引入jar包
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-words</artifactId> <version>21.11</version> <classifier>jdk17</classifier> <scope>system</scope> <systemPath>D:\data\aspose-words-21.11-jdk17.jar</systemPath> </dependency>
第五步:工具类并测试
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import com.aspose.words.Document; import com.aspose.words.SaveOptions; public class DocToPdf { public static void main(String[] args) throws FileNotFoundException { FileInputStream in = new FileInputStream("D:\\data\\示例.docx"); FileOutputStream out = new FileOutputStream(new File("D:\\data\\示例.pdf")); DocToPdf.convert(in, out); } /** * word 文件转pdf * * @param in word * @param out pdf */ public static void convert(InputStream in, OutputStream out) { try { Document document = new Document(in); document.save(out, SaveOptions.createSaveOptions("1.pdf")); } catch (Exception e) { throw new RuntimeException("文件转换失败"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } } } }
Word 转换 pdf 之后,发现带上了红色广告字和LOGO
第六步:将源码导入IDE,查询关键字 ".substring 定位到添加红色广告字方法 com.aspose.words.zzWwN.zzZKg(Document)
执行下列方法:
String str1 = zzWuq.zzXou(zzVu.zzIR().zzZ42(new byte[] { 118, 69, 108, 97, 97, 117, 105, 116, 110, 111, 79, 32, 108, 110, 46, 121, 67, 32, 101, 114, 116, 97, 100, 101, 119, 32, 116, 105, 32, 104, 115, 65, 111, 112, 101, 115, 87, 46, 114, 111, 115, 100, 32, 46, 111, 67, 121, 112, 105, 114, 104, 103, 32, 116, 48, 50, 51, 48, 123, 45, 125, 48, 65, 32, 112, 115, 115, 111, 32, 101, 116, 80, 32, 121, 116, 76, 46, 100 } ), new Object[] { "2021.11.01".substring(0, 4) }); String str2 = zzVu.zzIR().zzZ42(new byte[] { 114, 67, 97, 101, 101, 116, 32, 100, 105, 119, 104, 116, 97, 32, 32, 110, 118, 101, 108, 97, 97, 117, 105, 116, 110, 111, 99, 32, 112, 111, 32, 121, 102, 111, 65, 32, 112, 115, 115, 111, 46, 101, 111, 87, 100, 114, 46, 115, 84, 32, 32, 111, 105, 100, 99, 115, 118, 111, 114, 101, 116, 32, 101, 104, 102, 32, 108, 117, 32, 108, 101, 118, 115, 114, 111, 105, 115, 110, 111, 32, 32, 102, 117, 111, 32, 114, 80, 65, 115, 73, 112, 32, 101, 108, 115, 97, 32, 101, 105, 118, 105, 115, 58, 116, 104, 32, 116, 116, 115, 112, 47, 58, 112, 47, 111, 114, 117, 100, 116, 99, 46, 115, 115, 97, 111, 112, 101, 115, 99, 46, 109, 111, 119, 47, 114, 111, 115, 100, 47 }); String str3 = zzVu.zzIR().zzZ42(new byte[] { 104, 84, 115, 105, 100, 32, 99, 111, 109, 117, 110, 101, 32, 116, 97, 119, 32, 115, 114, 116, 110, 117, 97, 99, 101, 116, 32, 100, 101, 104, 101, 114, 98, 32, 99, 101, 117, 97, 101, 115, 105, 32, 32, 116, 97, 119, 32, 115, 114, 99, 97, 101, 101, 116, 32, 100, 110, 105, 116, 32, 101, 104, 69, 32, 97, 118, 117, 108, 116, 97, 111, 105, 32, 110, 111, 77, 101, 100, 46 }); String str4 = zzVu.zzIR().zzZ42(new byte[] { 115, 65, 111, 112, 101, 115, 87, 46, 114, 111, 115, 100, 82, 46, 115, 101, 117, 111, 99, 114, 115, 101, 65, 46, 112, 115, 115, 111, 76, 101, 103, 111, 46, 111, 110, 112, 103 }); System.out.println(str1); System.out.println(str2); System.out.println(str3); System.out.println(str4);
输出:
Evaluation Only. Created with Aspose.Words. Copyright 2003-2021 Aspose Pty Ltd. Created with an evaluation copy of Aspose.Words. To discover the full versions of our APIs please visit: https://products.aspose.com/words/ This document was truncated here because it was created in the Evaluation Mode. Aspose.Words.Resources.AsposeLogo.png
红色广告词找到了,推测所在方法就是添加广告及logo,直接修改方法为:
static void zzZKg(Document paramDocument) throws Exception { zzWan = 29273535023874148L; return; }
将该文件复制到测试项目,
进入target找到calss文件,用winrar 打开jar包替换字节码文件,删除.SF和RSA文件
用画图新建一个像素 AsposeLogo.png 替换掉jar包中的logo
重新生成效果:
参考:https://juejin.cn/post/7034387646168186894