Java如何实现Excel文件转PDF无水印无限制(excel,java,pdf,开发技术)

时间:2024-05-04 09:15:10 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

一、jar破解

1.项目远程仓库配置

aspose-cells 这个需要配置单独的仓库地址才能下载,不会配置的可以去官网直接下载jar引入项目代码中。

<repositories><repository><id>AsposeJavaAPI</id><name>AsposeJavaAPI</name><url>https://repository.aspose.com/repo/</url></repository></repositories>

2.pom文件引入相关依赖

<!--https://mvnrepository.com/artifact/com.aspose/aspose-cells--><dependency><groupId>com.aspose</groupId><artifactId>aspose-cells</artifactId><version>21.8</version></dependency><dependency><groupId>org.javassist</groupId><artifactId>javassist</artifactId><version>3.20.0-GA</version></dependency>

Javassist是一个开源的分析、编辑和创建Java字节码的类库。

3.代码破解

importjavassist.*;importjava.io.*;importjava.util.ArrayList;importjava.util.Enumeration;importjava.util.List;importjava.util.jar.JarEntry;importjava.util.jar.JarFile;importjava.util.jar.JarOutputStream;publicclassExcelJarCrack{publicstaticvoidmain(String[]args)throwsException{StringjarPath="C:\\Users\\liuya\\Desktop\\jar\\aspose-cells-21.8.jar";crack(jarPath);}privatestaticvoidcrack(StringjarName)throwsNotFoundException,CannotCompileException,IOException{//这一步是完整的jar包路径ClassPool.getDefault().insertClassPath(jarName);CtClassLicenseClass=ClassPool.getDefault().getCtClass("com.aspose.cells.License");CtMethod[]aMethods=LicenseClass.getDeclaredMethods("a");for(CtMethodaMethod:aMethods){CtClassreturnType=aMethod.getReturnType();if(returnType.getName().equals("boolean")){aMethod.setBody("{returntrue;}");break;}}//将文件名命名成备份文件Filefile=newFile(jarName);LicenseClass.writeFile(file.getParent());disposeJar(jarName);}privatestaticvoiddisposeJar(StringjarName){List<String>deletes=newArrayList<>();deletes.add("META-INF/37E3C32D.SF");deletes.add("META-INF/37E3C32D.RSA");List<String>replaces=newArrayList<>();replaces.add("com/aspose/cells/License.class");FileoriFile=newFile(jarName);if(!oriFile.exists()){System.out.println("######NotFindFile:"+jarName);return;}//将文件名命名成备份文件StringbakJarName=jarName.substring(0,jarName.length()-3)+"cracked.jar";try{//创建文件(根据备份文件并删除部分)JarFilejarFile=newJarFile(jarName);JarOutputStreamjos=newJarOutputStream(newFileOutputStream(bakJarName));Enumerationentries=jarFile.entries();while(entries.hasMoreElements()){JarEntryentry=(JarEntry)entries.nextElement();if(!deletes.contains(entry.getName())){if(replaces.contains(entry.getName())){System.out.println("Replace:-------"+entry.getName());JarEntryjarEntry=newJarEntry(entry.getName());jos.putNextEntry(jarEntry);FileInputStreamfin=newFileInputStream(oriFile.getParent()+"/"+entry.getName());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(FileNotFoundExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}catch(Exceptione){e.printStackTrace();}}privatestaticbyte[]readStream(InputStreaminStream)throwsException{ByteArrayOutputStreamoutSteam=newByteArrayOutputStream();byte[]buffer=newbyte[1024];intlen=-1;while((len=inStream.read(buffer))!=-1){outSteam.write(buffer,0,len);}outSteam.close();inStream.close();returnoutSteam.toByteArray();}}

修改为你本机的aspose-cells-21.8.jar路径,然后运行主方法,破解成功后,会再同级文件夹下生成一个aspose-cells-21.8.cracked.jar包,用这个包替换原来的aspose-pdf-21.8.jar包即可。

二、Excel转PDF

1.代码实现

importcom.aspose.cells.License;importcom.aspose.cells.SaveFormat;importcom.aspose.cells.Workbook;importjava.io.FileOutputStream;publicclassPdfUtils{publicstaticvoidmain(String[]args){excelToPdf("C:\\Users\\liuya\\Desktop\\excel\\test.xlsx");}/***Excel文件转换*@paramexcelPath需要被转换的excel全路径带文件名*@Returnvoid*/publicstaticvoidexcelToPdf(StringexcelPath){Licenselicense=newLicense();license.setLicense("C:\\Users\\liuya\\Desktop\\jar\\Aspose.License.xml");longold=System.currentTimeMillis();try{//新建一个pdf文档StringpdfPath=excelPath.substring(0,excelPath.lastIndexOf("."))+".pdf";//Excel文件数据Workbookwb=newWorkbook(excelPath);FileOutputStreamfileOS=newFileOutputStream(pdfPath);//保存为pdf文件wb.save(fileOS,SaveFormat.PDF);fileOS.close();//转化用时longnow=System.currentTimeMillis();System.out.println("EXCEL转Pdf共耗时:"+((now-old)/1000.0)+"秒");}catch(Exceptione){e.printStackTrace();}}}

2.Aspose.License.xml 授权文件

代码如下:

<License><Data><LicensedTo>AsposeScotlandTeam</LicensedTo><EmailTo>billy.lundie@aspose.com</EmailTo><LicenseType>DeveloperOEM</LicenseType><LicenseNote>Limitedto1developer,unlimitedphysicallocations</LicenseNote><OrderID>140408052324</OrderID><UserID>94236</UserID><OEM>Thisisaredistributablelicense</OEM><Products><Product>Aspose.TotalforJava</Product></Products><EditionType>Enterprise</EditionType><SerialNumber>9a59547c-41f0-428b-ba72-7c4368f151d7</SerialNumber><SubscriptionExpiry>20221231</SubscriptionExpiry><LicenseVersion>3.0</LicenseVersion><LicenseInstructions>http://www.aspose.com/corporate/purchase/license-instructions.aspx</LicenseInstructions></Data><Signature>FO3PHsblgDt8F59sMT1l1amyi9qk2V6E8dQkIP7LdTJSxDibNEFu1zOinQbqFfKv/ruttvcxoROkc1tUe0DtO6cP1Zf6J0VemgSY8i/LZECTGszRqJVQRZ0MoVnBhuPAJk5eli7fhVcF8hWd3E4XQ3LzfmJCuaj2NEteRi5Hrfg=</Signature></License>

因为jar已破解其核心验证方法,里面的签名可以随便填写,但是格式尽量保持一致,因为验证其他的格式方法还在!

运行成功截图

Java如何实现Excel文件转PDF无水印无限制

Java如何实现Excel文件转PDF无水印无限制

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Java如何实现Excel文件转PDF无水印无限制的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Go语言kylin任务自动化怎么实现下一篇:

86 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18