aspose-cells.jar实现Excel文件转换为PDF文件

5 篇文章 1 订阅

利用 aspose-cells-8.5.2.jar 实现 excel 内容转换为 pdf 文件输出。
开发过程中如果不验证 License 输出文件中会产生水印,详见如下 verifyLicense() 方法
主要实现代码:

/**
	 * @param src 需要被转换的excel全路径带文件名
	 * @param dest 转换之后pdf的全路径带文件名
	 * @throws GeneralException
	 */
	public static void convert(String src,String dest) throws GeneralException {
		// 验证License 若不验证则转化出的pdf文档会有水印产生
		if (!verifyLicense()) { 
			throw new GeneralException("License验证失败!");
		}
		try (FileOutputStream fileOS = new FileOutputStream(new File(dest));) {
			Workbook wb = new Workbook(src);
			wb.save(fileOS, com.aspose.cells.SaveFormat.PDF);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static boolean verifyLicense() {
		boolean result = false;
		try {
			InputStream is = Excel2pdfUtil.class.getResourceAsStream("/license.xml");
			License aposeLic = new License();
			aposeLic.setLicense(is);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

license.xml

<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>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值