当前位置: 代码迷 >> 综合 >> aspose-cells.jar实现Excel文件转换为PDF文件
  详细解决方案

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

热度:25   发布时间:2023-12-18 12:31:26.0

利用 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>
  相关解决方案