Aspose
1.工具类 AsposeUtil
package com.tx.web.controller.business.utils;
import java.io.*;
import com.aspose.cells.Workbook;
import com.aspose.slides.Presentation;
import com.aspose.words.*;
public class AsposeUtil{
public boolean getLicense() {
boolean result = false;
try {
InputStream is =this.getClass().getClassLoader().getResourceAsStream("license.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public boolean getLicenseExcel() {
boolean result = false;
try {
InputStream is =this.getClass().getClassLoader().getResourceAsStream("license.xml");
com.aspose.cells.License aposeLic = new com.aspose.cells.License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public boolean getLicensePpt(){
boolean result = false;
try {
InputStream is =this.getClass().getClassLoader().getResourceAsStream("license.xml");
com.aspose.slides.License aposeLic = new com.aspose.slides.License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws Exception {
AsposeUtil bean = new AsposeUtil();
bean.ppt2Pdf("D:\\pdf\\123.pptx","D:\\pdf\\1234.pdf");
}
public void word2Pdf2(String inpath,String outpath) throws Exception {
if (!getLicense()) {
System.out.println("非法------------");
return;
}
long old = System.currentTimeMillis();
File file = new File(outpath);
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(inpath);
doc.save(os, SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
}
public void word2pdf(String path, InputStream wordInput, String wordName) throws FileNotFoundException {
if (!getLicense()) {
System.out.println("非法");
return;
}
long old = System.currentTimeMillis();
File file = new File(path + wordName + ".pdf");
FileOutputStream os = new FileOutputStream(file);
Document doc = null;
try {
doc = new Document(wordInput);
} catch (Exception e) {
e.printStackTrace();
}
try {
doc.save(os, SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
}
public void excel2Pdf(String path,String outpath) throws FileNotFoundException {
FileOutputStream fileOutputStream = null;
if (!getLicenseExcel()) {
System.out.println("非法------------");
return;
}
File file = new File(outpath);
try {
Workbook wb = new Workbook(path);
fileOutputStream= new FileOutputStream(file);
wb.save(fileOutputStream, com.aspose.cells.SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void ppt2Pdf(String path,String outpath)throws FileNotFoundException{
if (!getLicensePpt()) {
System.out.println("非法------------");
return;
}
File file = new File(outpath);
try {
Presentation pres = new Presentation(path);
FileOutputStream fileOS = new FileOutputStream(file);
pres.save(fileOS, com.aspose.slides.SaveFormat.Pdf);
fileOS.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.license.xml
license.xml为水印破解,放在resources下面
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Words for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>
sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=
</Signature>
</License>
3.jar包引用以及地址
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-words-16.8.0-jdk16.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-cells-8.5.2.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose.slides-15.9.0.jar</systemPath>
</dependency>

jar包地址
4.jar package时 jar包没引用解决方案
在pom.xml里加入以下代码
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>