最近,需要将PPT文件转换为PDF。经过长时间的转换,一直有水印。最后,我找到了去除水印的方法来记录它。
自带jar包
链接:https://pan.baidu.com/s/IBJGQcnunbhlPDB7nppgpwd=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 */@SneakyThrowspublic static ByteArrayInputStream ppt2PDF(InputStream inputStream) {// Licenseiff验证 (!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 */@SneakyThrowspublic static ByteArrayInputStream ppt2PDF(InputStream inputStream) {// Licenseiff验证 (!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-4eff8-8ff0-acc37bf0d7</SerialNumber> </Data> <Signature>NLKGMUdF0r8okKilWGdfs2BvJb/2Xp8p5iudvfzxmpo+d0ran1P9TKdjv4ABWAKXJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pju=</Signature></License>
最后结果:
注:仅用于学习和交流,不用于商业用途!