admin管理员组文章数量:1593159
jar包破解
1、pom文件
分别复制进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、破解代码
复制粘贴修改一下路径,直接运行
package red.htt;
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.8.cracked.jar包,用这个包替换原来的aspose-pdf-21.8.jar包即可。
文章上面有jar包可直接下载替换
3、代码实现
package red.htt;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import java.io.*;
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();
}
}
}
搞定,收工!!!
版权声明:本文标题:java实现PDF转Word(无水印无页数限制)完全开放 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728165674a1147989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论