Aspose工具类,以及jar包

Aspose

1.工具类 AsposeUtil

package com.tx.web.controller.business.utils;


import java.io.*;

import com.aspose.cells.Workbook;
import com.aspose.slides.Presentation;
import com.aspose.words.*;

public class AsposeUtil{
    /**
     * 验证License 若不验证则转化出的pdf文档会有水印产生
     * @return
     */
    public  boolean getLicense() {
        boolean result = false;
        try {
            //引入license.xml文件,去除水印
            InputStream is =this.getClass().getClassLoader().getResourceAsStream("license.xml");
            //注意此处为apose-slides的jar包
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 验证License 若不验证则转化出的pdf文档会有水印产生
     * @return
     */
    public  boolean getLicenseExcel() {
        boolean result = false;
        try {

            InputStream is =this.getClass().getClassLoader().getResourceAsStream("license.xml");
            //注意此处为对应aspose-cells的jar包
            com.aspose.cells.License aposeLic = new com.aspose.cells.License();

            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 验证License 若不验证则转化出的pdf文档会有水印产生
     * @return
     */
    public boolean getLicensePpt(){
        boolean result = false;
        try {

            InputStream is =this.getClass().getClassLoader().getResourceAsStream("license.xml");
            //注意此处为对应aspose-slides的jar包
            com.aspose.slides.License aposeLic = new com.aspose.slides.License();

            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static void main(String[] args) throws Exception {
        AsposeUtil bean = new AsposeUtil();
//        bean.word2Pdf2("D:\\pdf\\12.docx","D:\\pdf\\12.pdf");
        bean.ppt2Pdf("D:\\pdf\\123.pptx","D:\\pdf\\1234.pdf");
    }

    /**
     * word转pdf
     * inpath: 输入word的路径
     * outpath: 输出pdf的路径
     */
    public  void word2Pdf2(String inpath,String outpath) throws Exception {
        if (!getLicense()) {
            System.out.println("非法------------");
            return;
        }

        long old = System.currentTimeMillis();
        File file = new File(outpath);

        FileOutputStream os = new FileOutputStream(file);

        //解决乱码
        //如果是windows执行,不需要加这个
        //TODO 如果是linux执行,需要添加这个*****
        //FontSettings.setFontsFolder("/usr/share/fonts",true);

        Document doc = new Document(inpath);

        //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
        doc.save(os, SaveFormat.PDF);

        long now = System.currentTimeMillis();
        System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
    }


    /**
     * word转pdf
     * @param path      pdf输出路径
     * @param wordInput word输入流
     * @param wordName  word文档的名称
     */
    public  void word2pdf(String path, InputStream wordInput, String wordName) throws FileNotFoundException {
        if (!getLicense()) {
            System.out.println("非法");
            return;
        }

        //新建一个空白pdf文档
        long old = System.currentTimeMillis();
        File file = new File(path + wordName + ".pdf");
        FileOutputStream os = new FileOutputStream(file);

        //Address是将要被转化的word文档
        Document doc = null;
        try {
            doc = new Document(wordInput);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
            doc.save(os, SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long now = System.currentTimeMillis();
        //转化用时
        System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
    }


    public void excel2Pdf(String path,String outpath) throws FileNotFoundException {
        FileOutputStream fileOutputStream = null;
        if (!getLicenseExcel()) {
            System.out.println("非法------------");
            return;
        }

        File file = new File(outpath);
        try {
            Workbook wb = new Workbook(path);
            fileOutputStream= new FileOutputStream(file);
            wb.save(fileOutputStream, com.aspose.cells.SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public void ppt2Pdf(String path,String outpath)throws FileNotFoundException{
        if (!getLicensePpt()) {
            System.out.println("非法------------");
            return;
        }
        File file = new File(outpath);

        try {
            Presentation pres = new Presentation(path);//输入pdf路径
            FileOutputStream fileOS = new FileOutputStream(file);
            pres.save(fileOS, com.aspose.slides.SaveFormat.Pdf);
            fileOS.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

2.license.xml

license.xml为水印破解,放在resources下面
<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>

3.jar包引用以及地址

        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/aspose-words-16.8.0-jdk16.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-cells</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/aspose-cells-8.5.2.jar</systemPath>
        </dependency>


        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-slides</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/aspose.slides-15.9.0.jar</systemPath>
        </dependency>

jar包放到resources下

jar包地址 提取码:peix

4.jar package时 jar包没引用解决方案

在pom.xml里加入以下代码
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
  • 31
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: Aspose.CAD是一个强大的CAD文件处理库,可以处理DWG、DXF等格式的CAD文件。想要使用Aspose.CAD,需要先下载Aspose.CAD的jar包,并添加到项目中。关于Aspose.CAD jar的下载,可以在Aspose官网上找到下载链接。Aspose官网提供了多种下载方式,如maven仓库、NuGet等,用户可以根据自己的需求选择合适的下载方式。在下载jar包之前,需要先注册Aspose官网账号,并获取相应的许可证。免费试用版的许可证可以让用户试用Aspose.CAD,但是需要在每个处理操作之前都加上许可证文件的设置,否则会导致处理结果出错。如果需要使用正式版的Aspose.CAD,需要购买许可证。购买许可证后,用户可以获得一定的技术支持和维护服务。总之,下载Aspose.CAD jar包需要注册Aspose账号、获取许可证,然后选择合适的下载方式。下载完成后,将Aspose.CAD jar包添加到项目中即可开始开发。 ### 回答2: Aspose CAD是一款功能强大的CAD文件处理工具,可以帮助程序员在Java应用程序中读取、编辑和转换CAD文件。为了使用Aspose CAD,您需要下载Aspose CAD Jar文件,这可以通过官方网站获得。 要下载Aspose CAD Jar文件,请遵循以下步骤: 1. 访问Aspose CAD官方网站。 2. 在网站主页面的菜单栏中,点击“产品”标签页。 3. 在产品列表中找到“Aspose.CAD for Java”并点击。 4. 在产品页面中,您将找到有关该产品的所有详细信息,包括产品文档、示例和下载链接。 5. 单击“下载”按钮,该按钮位于页面右侧。 6. 在“下载”页面中,选择Aspose CAD的版本和JAR文件以及所需的操作系统。 7. 单击“下载”按钮,即可获取Aspose CAD Jar文件。 一旦您下载了Aspose CAD Jar文件,就可以在您的Java应用程序中使用它了。只需将Jar文件添加到您的项目中即可开始使用Aspose CAD的强大功能。通过Aspose CAD,您可以轻松地读取、编辑和转换CAD文件,以便为您的项目添加更多功能和灵活性。 ### 回答3: Aspose CAD是一款专业的CAD文件处理工具,其Java版的jar包可以通过官方网站进行下载。首先需要注册Aspose账户并获取许可证,然后在官网上找到Aspose CAD for Java的页面,点击“Download”按钮即可开始下载。下载的压缩包中包含了Aspose CAD的jar文件以及相关的示例代码和文档。 下载完成后,可以将Aspose CAD的jar包添加到项目中使用。具体方法为,在项目中引入Aspose CAD的jar包并进行类导入,然后利用Aspose CAD提供的API对CAD文件进行编辑、转换和提取等操作。 需要注意的是,使用Aspose CAD需要付费购买许可证才能进行商业化使用。同时,Aspose CAD也提供了免费的30天试用期,可以先进行试用再决定是否购买许可证。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值