最近有个需求需要把PPT文件转为PDF,整了好久转换完成一直都是有水印的,最终终于找到了去水印的办法,记录一下。
jar包自取
链接:https://pan.baidu.com/s/1IBJGQcnuNBhlPDb7nPpDPg?pwd=fJrs
提取码:fJrs
嫌百度网盘慢的可以用下方阿里云盘链接
本地安装jar命令:
mvn install:install-file -Dfile="C:/Users/DELL/Desktop/aspose.slides-15.9.0.jar" -DgroupId=com.aspose -DartifactId=aspose-slides -Dversion=15.9.0 -Dpackaging=jar
下面上代码块(全部的看下面AsposeUtil代码):
/**
* ppt to pdf
* @param inputStream
*/
@SneakyThrows
public static ByteArrayInputStream ppt2PDF(InputStream inputStream) {
// 验证License
if (!getLicenseq()) {
return null;
}
try {
Presentation ppt = new Presentation(inputStream);
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
ppt.save(dstStream, com.aspose.slides.SaveFormat.Pdf);
ByteArrayInputStream inputStream1 = parse(dstStream);
return inputStream1;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* licence 验证
*
* @return
* @throws Exception
*/
public static boolean getLicenseq() throws Exception {
boolean result = false;
try {
InputStream is = AsposeUtil.class
.getResourceAsStream("/slides/license.xml");
com.aspose.slides.License aposeLic = new com.aspose.slides.License();
aposeLic.setLicense(is);
result = true;
is.close();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return result;
}
AsposeUtil 类
import com.aspose.slides.Presentation;
import com.aspose.words.*;
import com.aspose.words.Shape;
import lombok.SneakyThrows;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @author 不敢喝雪碧 我怕心飞扬
* @version
*/
public class AsposeUtil {
private static InputStream slides;
/**
* licence 验证
*
* @return
* @throws Exception
*/
public static boolean getLicenseq() throws Exception {
boolean result = false;
try {
InputStream is = AsposeUtil.class
.getResourceAsStream("/slides/license.xml");
com.aspose.slides.License aposeLic = new com.aspose.slides.License();
aposeLic.setLicense(is);
result = true;
is.close();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return result;
}
/**
* ppt to pdf
* @param inputStream
*/
@SneakyThrows
public static ByteArrayInputStream ppt2PDF(InputStream inputStream) {
// 验证License
if (!getLicenseq()) {
return null;
}
try {
Presentation ppt = new Presentation(inputStream);
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
ppt.save(dstStream, com.aspose.slides.SaveFormat.Pdf);
ByteArrayInputStream inputStream1 = parse(dstStream);
return inputStream1;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
license.xml
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>29991231</SubscriptionExpiry>
<LicenseExpiry>29991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>
最后结果:
注:仅用于学习和交流,切勿用于商业用途!