Aspose简介

Aspose.Total是Aspose公司旗下全套文件格式处理解决方案,提供最完整、最高效的文档处理解决方案集,无需任何其他软件安装和依赖。主要提供.net、java、C++d三个开发语言的工具包,通过它,可以对办公文档格式的转换和文档内容的在线编辑,如:Word, Excel, PowerPoint, PPT,图片,PDF等文档。 另外,Aspose.Total 还提供了用于写邮件、拼写检查、创建条形码、OCR和3D等等。

使用样例(22.3版本)

以下列举几种常用的文档格式转换样例,对于Aspose.Total来说,这几个功能只是它的冰山一角。

1.excel转pdf:

  1. public static long excelToPdf(String inFile, String outFile) throws Exception {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) {
  3. return 0;
  4. }
  5. try {
  6. long old = System.currentTimeMillis();
  7. File pdfFile = new File(outFile);
  8. Workbook wb = new Workbook(inFile);
  9. PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
  10. pdfSaveOptions.setOnePagePerSheet(true);
  11. FileOutputStream fileOS = new FileOutputStream(pdfFile);
  12. wb.save(fileOS, SaveFormat.PDF);
  13. fileOS.close();
  14. long now = System.currentTimeMillis();
  15. Out.print(inFile, outFile, now, old);
  16. return pdfFile.length();
  17. }catch (Exception e) {
  18. e.printStackTrace();
  19. throw new Exception(e.getMessage());
  20. }
  21.  
  22. }

2.pdf转excel:

  1. public static long pdfToExcel(String inFile, String outFile) throws Exception {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
  3. return 0;
  4. }
  5. try {
  6. long old = System.currentTimeMillis();
  7. Document doc = new Document(inFile);
  8. ExcelSaveOptions options = new ExcelSaveOptions();
  9. options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);
  10. doc.save(outFile, options);
  11. Out.print(inFile, outFile, System.currentTimeMillis(), old);
  12. return new File(outFile).length();
  13. }catch (Exception e) {
  14. e.printStackTrace();
  15. throw new Exception(e.getMessage());
  16. }
  17. }

3.word转pdf:

  1. public static long wordToPdf(String inFile, String outFile) throws Exception {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getWordLicense()) {
  3. return 0;
  4. }
  5. try {
  6. long old = System.currentTimeMillis();
  7. File file = new File(outFile);
  8. FileOutputStream os = new FileOutputStream(file);
  9. Document doc = new Document(inFile);
  10. Document tmp = new Document();
  11. tmp.removeAllChildren();
  12. tmp.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
  13. System.out.println("开始解析word文档" + inFile);
  14. doc.save(os, SaveFormat.PDF);
  15. long now = System.currentTimeMillis();
  16. log.info("target file size:{}",file.length());
  17. os.close();
  18. Out.print(inFile, outFile, now, old);
  19. return file.length();
  20. } catch (Exception e) {
  21. log.error(inFile + "转换失败,请重试",e);
  22. throw new Exception(e.getMessage());
  23. }
  24. }

4.pdf转word:

  1. public static long pdfToDoc(String inFile, String outFile) {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
  3. return 0;
  4. }
  5. log.info("开始转换...");
  6. long old = System.currentTimeMillis();
  7. Document pdfDocument = new Document(inFile);
  8. DocSaveOptions saveOptions = new DocSaveOptions();
  9. /** 或者DocSaveOptions.DocFormat.DocX*/
  10. saveOptions.setFormat(DocSaveOptions.DocFormat.Doc);
  11. pdfDocument.save(outFile, saveOptions);
  12. long now = System.currentTimeMillis();
  13. Out.print(inFile, outFile, now, old);
  14. log.info("转换结束...");
  15. return new File(outFile).length();
  16. }

5.ppt转pdf:

  1. public static long pptToPdf(String inFile, String outFile) throws Exception {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getPptLicense()) {
  3. return 0;
  4. }
  5. try {
  6. long old = System.currentTimeMillis();
  7. File pdfFile = new File(outFile);
  8. FileOutputStream os = new FileOutputStream(pdfFile);
  9. Presentation pres = new Presentation(inFile);
  10. pres.save(os, com.aspose.slides.SaveFormat.Pdf);
  11. os.close();
  12. long now = System.currentTimeMillis();
  13. Out.print(inFile, outFile, now, old);
  14. return pdfFile.length();
  15. } catch (Exception e) {
  16. e.printStackTrace();
  17. throw new Exception(e.getMessage());
  18. }
  19. }

6.pdf转ppt:

  1. public static long pdfToPpt(String inFile, String outFile) {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
  3. return 0;
  4. }
  5. long old = System.currentTimeMillis();
  6. Document pdfDocument = new Document(inFile);
  7. PptxSaveOptions pptxOptions = new PptxSaveOptions();
  8. pptxOptions.setExtractOcrSublayerOnly(true);
  9. pdfDocument.save(outFile, pptxOptions);
  10. long now = System.currentTimeMillis();
  11. Out.print(inFile, outFile, now, old);
  12. return new File(outFile).length();
  13. }

7.odt转pdf:

  1. public static long odtToPdf(String inFile, String outFile) throws Exception {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getWordLicense()) {
  3. return 0;
  4. }
  5. try {
  6. long old = System.currentTimeMillis();
  7. Document doc = new Document(inFile);
  8. doc.save(outFile);
  9. long fileSize = new File(outFile).length();
  10. long now = System.currentTimeMillis();
  11. log.info("target file size:{}",fileSize);
  12. Out.print(inFile, outFile, now, old);
  13. return fileSize;
  14. } catch (Exception e) {
  15. log.error(inFile + "转换失败,请重试",e);
  16. throw new Exception(e.getMessage());
  17. }
  18. }

8.pdf转图片:

  1. public static long pdfToPng(String inFile, List<String> outFile) throws Exception {
  2. long size = 0;
  3. if (!com.yrnet.transfer.business.transfer.file.License.getPdfLicense()) {
  4. return size;
  5. }
  6. try {
  7. long old = System.currentTimeMillis();
  8. Document pdfDocument = new Document(inFile);
  9. Resolution resolution = new Resolution(960);
  10. JpegDevice jpegDevice = new JpegDevice(resolution);
  11. for (int index=1;index<=pdfDocument.getPages().size();index++) {
  12. String path = inFile.substring(0,inFile.lastIndexOf(".")) + "_"+index+".png";
  13. File file = new File(path);
  14. size += file.length();
  15. FileOutputStream fileOs = new FileOutputStream(file);
  16. jpegDevice.process(pdfDocument.getPages().get_Item(index), fileOs);
  17. outFile.add(path);
  18. fileOs.close();
  19. long now = System.currentTimeMillis();
  20. Out.print(inFile, path, now, old);
  21. }
  22. return size;
  23. }catch (Exception e){
  24. log.error(e.getMessage(),e);
  25. throw new Exception(e.getMessage());
  26. }
  27. }

9.excel转图片:

  1. public static long excelToPic(String inFile, String outFile) throws Exception {
  2. if (!com.yrnet.transfer.business.transfer.file.License.getExcelLicense()) {
  3. return 0;
  4. }
  5. try {
  6. long old = System.currentTimeMillis();
  7. Workbook wb = new Workbook(inFile);
  8. Worksheet sheet = wb.getWorksheets().get(0);
  9. ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
  10. imgOptions.setImageFormat(ImageFormat.getPng());
  11. imgOptions.setCellAutoFit(true);
  12. imgOptions.setOnePagePerSheet(true);
  13. SheetRender render = new SheetRender(sheet, imgOptions);
  14. render.toImage(0, outFile);
  15. long now = System.currentTimeMillis();
  16. Out.print(inFile, outFile, now, old);
  17. return new File(outFile).length();
  18. }catch (Exception e) {
  19. e.printStackTrace();
  20. throw new Exception(e.getMessage());
  21. }
  22. }

10. ...

为什么要破解

官方提供免费的试用,转换出来是带有水印和次数限制的。所以想要绕过许可的困扰。只有两个办法:购买和破解。

从官方的更新频率来看,基本上一个月左右一个版本,所说官方比较重视并重点投入这个项目,同时也说明软件存在待优化的bug。其实在21版本之前有很多转换上的兼容问题,如:

布局错位、特殊符号无法识别,表格内容错乱等造成转换后文档阅读障碍。对于内容要求搞的使用场景来说,无法使用在生产上。

以上主要对最新的22版本进行破解(笔者破解的时候官方发布最新的是22.3版本)

破解方法

  • 破解思路:每个工具包都有对应的License类,这个类是检验许可和授权的入口。从该类入手,慢慢研究反编译后的源码,但其实它使用了混淆手断,使得反编译后的代码看起来比较吃力。

即使如此,对于破解并不是干扰太大,我们不需要去弄清楚每一行,甚至每个方法的功能。破解的任务是移除校验授权对应的代码块或方法。

最简单也是最有效的办法就是直接删除,在这里羚羊就不一一带入分析源码的坑了。下面直接提供现成的包。

  • 破解工具:源码弄不下来,不能像老套路一样,修改对应源码后再对着整个套源码重新编译一遍。怎么办?只能对着目标class文件直接修改保存并覆盖原class文件。在这羚羊推荐三个比较方便使用的工具:

一、JByteMod

这个是界面化工具,修改比较方便,直接把目标jar打开,找到目标的类方法,然后对着要删除的操作指令右键删除保存即可

二、javassist

界面化的JByteMod,虽然小白都可以使用。但有时候你删除不对,甚至从直观上删除操作指令后没有破坏整个class文件,但是却无法使用,比如报方法不存在、class检验异常等。遇到这种情况的时候,使用javassist就灵活,成功率高很多。如:

  1. public void testMod_words1(){
  2. try {
  3. ClassPool.getDefault().insertClassPath("/Users/dengbp/Downloads/doc-sys/pdf-transfer/src/lib/aspose-words-22.3.0-jdk17.jar");
  4. CtClass zzZJJClass = ClassPool.getDefault().getCtClass("com.aspose.words.zzP6");
  5. CtMethod methodB = zzZJJClass.getDeclaredMethod("zzWMy");
  6. methodB.setBody("{return 256;}");
  7. zzZJJClass.writeFile("/Users/dengbp/Downloads/");
  8. } catch (Exception e) {
  9. System.out.println("错误==" + e);
  10. }
  11. }

三、asm

javassist是基于java编程去修改源码内容,而相对于asm,它跟界面化的JByteMod一样,都是直接对jvm的指令去修改。如:

成品贡献(22.3版本)

链接: https://pan.baidu.com/s/13DcNlLsrzlU_1j6pniRGhw  密码: ***

需要jar包,请私聊,V:dbp168

PS:本文仅用于参考学习,请勿用于商业用途

Aspose最新版文档格式转换使用破解的更多相关文章

  1. windwos文档格式转换成unix格式

    在工作学习中我们避免不了需要将一些脚本和命令记录在笔记里面,我使用的是有道云笔记,每当我将上次记录在有道云的脚本复制出来进行使用的时候,总会报一些奇怪的错误,要么是包含换行符,要么就是格式不对,但是我 ...

  2. Java利用jacob实现文档格式转换

    实现文档格式之间的转换,我使用的是jacob-1.7版本,需要jacob.jar来调用activex控件,本机需安装WPS/office,还需要jacob.jar以及jacob.dll 其中:    ...

  3. Python - 文档格式转换(CSV与JSON)

  4. 【好文翻译】一步一步教你使用Spire.Doc转换Word文档格式

    背景: 年11月,微软宣布作为ECMA国际主要合作伙伴,将其开发的基于XML的文件格式标准化,称之为"Office Open XML" .Open XML的引进使office文档结 ...

  5. C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化

    转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...

  6. 导出WPS office文档格式的说明

     针对microsoft office的文档格式,WPS office分别提供wps对应doc,et对应xls两种格式,word和excel是办公系统使用的普及度最广的文件格式,而国内的政府行政单 ...

  7. 【itext】7步制作兼容各种文档格式的Itext5页眉页脚 实现page x pf y

    itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...

  8. Java导出freemarker实现下载word文档格式功能

    首先呢,先说一下制作freemarker模板步骤, 1. 在WPS上写出所要的下载的word格式当做模板 2. 把模板内不固定的内容(例:从数据库读取的信息)写成123或者好代替的文字标注 3. 把固 ...

  9. wordxml文档格式说明

    近期需要对word xml文档进行各种操作,需要熟悉 wordxml 文档格式,搜索了一番后发现 open xml sdk 官网的文档最好.就按照官网说明来记录一番 1 word xml 文档基本格式 ...

随机推荐

  1. 聊聊buffer和cache的区别以及是什么?

    buffer 众所周知,想把数据写入磁盘,肯定要先把数据文件读到内存中,当修改完这个文件时,不会立即写入磁盘,为了减少磁盘IO,提高性能,所有会留存一段时间再写入磁盘,这就是buffer cache ...

  2. Django学习——静态文件配置、request对象方法、pycharm如何链接数据库、Django如何指定数据库、Django orm操作

    静态文件配置 # 1.静态文件 网站所使用的已经提前写好的文件 css文件 js文件 img文件 第三方文件 我们在存储静态文件资源的时候一般默认都是放在static文件夹下 # 2.Django静态 ...

  3. 论文解读(Graphormer)《Do Transformers Really Perform Bad for Graph Representation?》

    论文信息 论文标题:Do Transformers Really Perform Bad for Graph Representation?论文作者:Chengxuan Ying, Tianle Ca ...

  4. Linux服务器安全加固10条建议

    以下是服务器安全加固的步骤,本文以腾讯云的CentOS7.7版本为例来介绍,如果你使用的是秘钥登录服务器1-5步骤可以跳过. 设置复杂密码 服务器设置大写.小写.特殊字符.数字组成的12-16位的复杂 ...

  5. 使用NFS作为Glance存储后端

    NFS服务介绍 NFS网络文件系统提供了一种在类UNIX系统上共享文件的方法.目前NFS有3个版本:NFSv2.NFSv3.NFSv4.CentOS7默认使用NFSv4提供服务,优点是提供了有状态的连 ...

  6. call()、apply()、arguments

    一.call(),apply() 1.作为函数对象(指函数方法名,不带括号)的方法,需要通过函数对象调用:当对函数调用这两个方法时都会调用函数执行. <script> // 这个函数中,f ...

  7. 109_Power Pivot客户ABC(帕累托)分析度量值写法(非计算列)

    博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载附件 1.背景 客户ABC分析,一般的套路是在计算列中把客户ABC分类,便于后续维度使用.今天用度量值的方式写一个ABC的分类. ...

  8. ethtools-网卡适配器管理

    查看网卡适配器配置信息,并且我们可以通过它修改网卡适配器的双工模式. 1.安装Ethtools [root@localhost ~]# yum -y install ethtools 2.命令语法 语 ...

  9. Es图形化软件使用之ElasticSearch-head、Kibana,Elasticsearch之-倒排索引操作、映射管理、文档增删改查

    今日内容概要 ElasticSearch之-ElasticSearch-head ElasticSearch之-安装Kibana Elasticsearch之-倒排索引 Elasticsearch之- ...

  10. CabloyJS也有工作流引擎了,是你想要的吗?

    前言 众所周知,NodeJS作为后端开发语言和运行环境,样样都好,就差一个NodeJS工作流引擎.CabloyJS 4.0重点开发了NodeJS工作流引擎,并作为内置的基础核心模块,近一步拓展了Nod ...