使用com.aspose 文件转html/pdf

license

<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>

1.word转html
 

InputStream license = Class.class.getClassLoader().getResourceAsStream("license文件路径");
 com.aspose.words.License loadLic = new com.aspose.words.License();
        loadLic.setLicense(license);
com.aspose.words.Document wb = new com.aspose.words.Document("word文件");
     HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        saveOptions.setExportImagesAsBase64(true);
        saveOptions.setExportTextInputFormFieldAsText(false);
        wb.save(out, saveOptions);

2.excel转html

 InputStream license = Class.class.getClassLoader().getResourceAsStream("license文件路径");
        com.aspose.cells.License loadLic = new com.aspose.cells.License();
        loadLic.setLicense(license);
        Workbook excel = new Workbook("excel文件");
        excel.save(out, com.aspose.cells.SaveFormat.HTML);

3.ppt转html

        InputStream license = Class.class.getClassLoader().getResourceAsStream("license路径");
        com.aspose.slides.License loadLic = new com.aspose.slides.License();
        loadLic.setLicense(license);
        Presentation ppt = new Presentation("文件");
        ppt.save(out, com.aspose.slides.SaveFormat.Pdf);

4.word转pdf

      InputStream license = Class.class.getClassLoader().getResourceAsStream("license路径");
        com.aspose.words.License license1 = new com.aspose.words.License();
        license1.setLicense(license);
        OutputStream fileOutputStream1 = new FileOutputStream("pdf文件路径");
        com.aspose.words.Document wb = new com.aspose.words.Document("word文件路径");
        wb.save(fileOutputStream1, SaveFormat.PDF);

5.excel转pdf

public static ByteArrayOutputStream excel2Pdf(InputStream fileStream) throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream license = Class.class.getClassLoader().getResourceAsStream("license路径");
        com.aspose.cells.License loadLic = new com.aspose.cells.License();
        loadLic.setLicense(license);
        IndividualFontConfigs configs = new IndividualFontConfigs();
		//加载字体文件
        configs.setFontFolder("字体文件夹路径", true);
        LoadOptions loadOptions  = new LoadOptions();
        loadOptions.setFontConfigs(configs);
        Workbook excel = new Workbook(fileStream, loadOptions);
        // 设置pdf保存的格式以及强制所有列都在同一页
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setOnePagePerSheet(true);
        excel.save(out, pdfSaveOptions);
        return out;
    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值