破解 Aspose-PDF 的 Jar 包
下载官方包
下载地址:aspose
文档地址: aspose 文档
破解
创建一个破解类
import com.aspose.pdf.HtmlDocumentType; import com.aspose.pdf.HtmlSaveOptions; import com.aspose.pdf.SaveFormat; import com.aspose.pdf.SaveOptions; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import org.apache.commons.compress.utils.IOUtils; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; public class PDFTest { public static void main(String[] args) throws Exception { // 这个是jar包的存放路径 String jarPath = "/Downloads/aspose-pdf-24.10.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/7DD91000.SF"); deletes.add("META-INF/7DD91000.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(); } }
运行后会在原来的文件生成文件
测试运行
导入项目中
选中项目右键 > 选择 Open Module Settings
编写代码把 PDF 转 HTML
import com.aspose.pdf.HtmlDocumentType; import com.aspose.pdf.HtmlSaveOptions; import com.aspose.pdf.SaveFormat; import com.aspose.pdf.SaveOptions; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import org.apache.commons.compress.utils.IOUtils; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; public class PDFTest { public static void main(String[] args) throws Exception{ String file1 = "/Downloads/aspose/test1.pdf"; pdfToHtml(file1,"/Downloads/aspose/test.html"); } /** * * @param sourceFile * @param targetFile */ public static void pdfToHtml(String sourceFile, String targetFile) { try { long old = System.currentTimeMillis(); System.out.println("开始转换"); FileOutputStream os = new FileOutputStream(targetFile); /** * HtmlDocumentType.Html5: 生成 HTML5 格式的文档,支持现代浏览器的特性 * HtmlDocumentType.Xhtml: 生成 XHTML 格式的文档,适用于严格的 XML 兼容性 * true: 表示生成的 HTML 将采用固定布局,页面内容的尺寸和位置将保持不变 * false: 表示生成的 HTML 将采用流式布局,内容可能会根据浏览器窗口的大小进行调整 */ HtmlSaveOptions options = new HtmlSaveOptions(HtmlDocumentType.Html5,true); /** * AsPngImagesEmbeddedIntoSvg: 将图像嵌入到 SVG 文件中作为 PNG 图像。这种方式可以保持图像的质量,同时将所有内容嵌套在一个文件中,便于管理和传输 * AsExternalPngFilesReferencedViaSvg: 将图像保存为外部 PNG 文件,并通过 SVG 文件引用这些外部文件。这意味着生成的 HTML 或 SVG 文件将指向外部 PNG 图像,而不是将其嵌入 * AsEmbeddedPartsOfPngPageBackground:将图像嵌入为页面背景的一部分,作为 PNG 图像的一部分。这会将图像直接嵌入到页面的背景中,确保在不同环境下都能一致显示 */ options.setRasterImagesSavingMode(HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground); /** * AlwaysSaveAsWOFF: 始终将字体保存为 WOFF(Web Open Font Format)格式。这种格式特别适合于网页使用,因为它经过压缩并优化以提高加载速度 * AlwaysSaveAsTTF: 始终将字体保存为 TTF(TrueType Font)格式。TTF 是一种广泛使用的字体格式,兼容性强,适用于多种平台 * AlwaysSaveAsEOT: 始终将字体保存为 EOT(Embedded OpenType)格式。这种格式主要用于 Internet Explorer * SaveInAllFormats: 将字体保存为所有支持的格式(如 WOFF、TTF 和 EOT)。这确保了在不同环境和浏览器中都能使用字体 * DontSave: 不保存任何字体。这意味着在生成的 HTML 中将不会包含任何字体文件 */ options.setFontSavingMode(HtmlSaveOptions.FontSavingModes.SaveInAllFormats); /** * EmbedAllIntoHtml: 将所有相关的资源(包括 CSS、图像等)嵌入到生成的 HTML 文件中。这意味着生成的 HTML 文件将包含所有必要的样式和图像,方便在任何环境中独立使用。 * EmbedCssOnly: 仅将 CSS 文件嵌入到生成的 HTML 文件中,其他资源(如图像)将不嵌入。这种方式使得样式在 HTML 中保持独立,但图像仍然需要外部引用 * NoEmbedding: 不嵌入任何资源。这意味着生成的 HTML 文件将引用外部的 CSS 和图像文件,所有资源都需要在外部存在 */ options.setPartsEmbeddingMode(HtmlSaveOptions.PartsEmbeddingModes.EmbedCssOnly); /** * true: 将每个 PDF 页面转换为单独的 HTML 文件。每个文件将命名为 output_1.html、output_2.html 等 * false: 将整个 PDF 文档转换为单个 HTML 文件。 */ options.setSplitIntoPages(true); /** * 转换指定页面 */ // options.setExplicitListOfSavedPages(new int[]{106}); /** * true: 在生成的 HTML 中对 SVG 图形进行压缩。这将减少文件大小,可能提高加载速度 * false: 不对 SVG 图形进行压缩,保留原始图形的完整性。 */ options.setCompressSvgGraphicsIfAny(false); /** *true: 将带阴影的文本转换为透明文本。这意味着阴影效果将不再被视为单独的元素,而是与文本合并为透明效果 *false: 带阴影的文本将保持为常规文本,阴影效果将作为单独的图形元素保留。 */ options.setSaveShadowedTextsAsTransparentTexts(true); /** *true: 将标记的内容(如裁剪、透明度等)转换为图层。这可以提高在某些应用程序或浏览器中的渲染效果 *false: 不将标记的内容转换为图层,所有内容将作为单一图形处理 */ options.setConvertMarkedContentToLayers(true); /** *true: 使用 Z 轴顺序来确定图形的绘制顺序。具有更高 Z 值的元素将覆盖具有较低 Z 值的元素 *false: 不考虑 Z 轴顺序,元素的绘制顺序将基于它们在文档中的顺序 */ options.setUseZOrder(true); /** *WriteAllHtml: 生成完整的 HTML 文档,包括 <html>、<head> 和 <body> 标签。这种模式适用于需要完整 HTML 页面的场景,便于在浏览器中直接加载和展示 * WriteOnlyBodyContent: 仅生成 HTML 文档的 <body> 内容,不包括 <html> 和 <head> 标签。这种模式适用于需要将内容嵌入到现有页面中的场景,或者当您只关心页面主体内容时。 */ options.setHtmlMarkupGenerationMode(HtmlSaveOptions.HtmlMarkupGenerationModes.WriteAllHtml); /** *true: 将透明文本保留在生成的 HTML 文件中。这意味着如果 PDF 中的文本有透明效果,这些效果将被保留 *false: 不保存透明文本,透明效果将被忽略,文本将以不透明的形式呈现 */ options.setSaveTransparentTexts(true); /** *true: 将 CSS 文件按照页面拆分,生成多个 CSS 文件,每个文件对应 PDF 文档中的一个页面。这在需要对每个页面的样式进行单独管理时非常有用 *false: 不拆分 CSS,所有样式将保存在一个单独的 CSS 文件中。适合于希望整体管理样式的场景 */ options.setSplitCssIntoPages(false); // 设置自定义资源保存策略,这里保存存的是图片资源 options.setCustomResourceSavingStrategy(new HtmlSaveOptions.ResourceSavingStrategy() { @Override public String invoke(SaveOptions.ResourceSavingInfo resourceSavingInfo) { // 实现自定义的资源保存逻辑 String resourceUri = resourceSavingInfo.getSupposedFileName(); String path = "/Downloads/aspose/image/"+resourceSavingInfo.getSupposedFileName(); try(FileOutputStream fileOutputStream = new FileOutputStream(path)){ fileOutputStream.write(resourceSavingInfo.getContentStream()); fileOutputStream.flush(); long now = System.currentTimeMillis(); System.out.println("保存文件"+"共耗时:" + ((now - old) / 1000.0) + "秒" + " "+path); }catch (Exception e){ e.printStackTrace(); } return path; } }); //这里保存的是Html资源 options.setCustomHtmlSavingStrategy(new HtmlSaveOptions.HtmlPageMarkupSavingStrategy() { @Override public void invoke(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlPageMarkupSavingInfo) { long now = System.currentTimeMillis(); System.out.println("invoke 共耗时:" + ((now - old) / 1000.0) + "秒"+" "+htmlPageMarkupSavingInfo.getSupposedFileName()); //转化用时 String path = "/Users/yudong/Downloads/aspose/html/"+htmlPageMarkupSavingInfo.getSupposedFileName(); try(FileOutputStream fileOutputStream = new FileOutputStream(path)){ InputStream inputStream = htmlPageMarkupSavingInfo.getContentStream(); byte[] buffer = new byte[4096]; // 创建缓冲区 int bytesRead; // 将 InputStream 的内容写入 FileOutputStream while ((bytesRead = inputStream.read(buffer)) != -1) { fileOutputStream.write(buffer, 0, bytesRead); } }catch (Exception e){ e.printStackTrace(); } } }); com.aspose.pdf.Document doc = new com.aspose.pdf.Document(sourceFile);//加载源文件数据 doc.save("/Downloads/aspose/test.html", options);//设置转换文件类型并转换 os.close(); long now = System.currentTimeMillis(); System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时 } catch (Exception e) { e.printStackTrace(); } } }
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于