Java PPT转PDF 亲测无水印

最近有个需求需要把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>

最后结果:

注:仅用于学习和交流,切勿用于商业用途!

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值