word excel ppt转pdf

1.excel转pdf

复制代码
package pers.wwz.study;

import com.aspose.cells.PdfSaveOptions;
import com.aspose.cells.Workbook;
 
public class ExcelToPdf {
    public static void main(String[] args) throws Exception {
        // 加载Excel文件
        Workbook workbook = new Workbook("D:\\tmp\\test.xlsx");
 
        // 创建PDF保存选项
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
 
        // 转换并保存为PDF
        workbook.save("D:\\tmp\\aspose_excel2pdf.pdf", pdfSaveOptions);
    }
}

2.word转pdf

复制代码
package pers.wwz.study;

import com.aspose.words.*;

public class WordToPdfTest_Aspose {

    public static void main(String[] args) throws Exception {

        wordToPdf("/Users/ascendking/Desktop/1.docx","/Users/ascendking/Desktop/aspose_word2pdf.pdf");
    }

    public static void wordToPdf(String wordFile, String pdfFile) throws Exception {
        Document wordDoc = new Document(wordFile);
        PdfSaveOptions pso = new PdfSaveOptions();
        wordDoc.save(pdfFile, pso);
    }
}

3ppt转pdf

复制代码
package pers.wwz.study;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.slides.License;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;

/**
 * 
 * 由于ASPOSE比较吃内存,操作大一点的文件就会堆溢出,所以请先设置好java虚拟机参数:-Xms512m -Xmx512m(参考值)<br>
 * 
 * 如有疑问,请在CSDN下载界面留言,或者联系QQ569925980<br>
 * 
 * @author Spark
 *
 */
public class Ppt2Pdf {

    private static InputStream license;
    private static InputStream slides;

    /**
     * 获取license
     * 
     * @return
     */
    public static boolean getLicense() {
        boolean result = false;
        try {
            license = Ppt2Pdf.class.getClassLoader().getResourceAsStream("slides_license.xml");// license路径
            slides = Ppt2Pdf.class.getClassLoader().getResourceAsStream("test.pptx");// 原始ppt路径
            License aposeLic = new License();
            aposeLic.setLicense(license);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 
     * @param args
     */
    public static void main(String[] args) {
        // 验证License
        if (!getLicense()) {
            return;
        }

        try {
            long old = System.currentTimeMillis();
            Presentation pres = new Presentation(slides);
            File file = new File("D:\\tmp\\aspose_pptx2pdf.pdf");// 输出pdf路径
            FileOutputStream fileOS = new FileOutputStream(file);

            pres.save(fileOS, SaveFormat.Pdf);

            long now = System.currentTimeMillis();
            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒\n\n" + "文件保存在:" + file.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
相关推荐
DreamNotOver21 小时前
批量转换论文正文引用为上标后转PDF保持上标
pdf·word·引用·上标
PPT百科1 天前
PPT插入的音乐怎么让它播放到某一页就停?
大数据·职场和发展·powerpoint·职场·ppt模板
郏国上1 天前
查询数据库上所有表用到图片和视频的数据,并记录到excel表
mongodb·node.js·excel
OICQCO1 天前
WPS Excel 图表
excel·wps
装不满的克莱因瓶1 天前
【项目亮点】基于EasyExcel + 线程池解决POI文件导出时的内存溢出及超时问题
java·jvm·excel·线程池·async·虚拟机·easyexcel
njsgcs1 天前
excel提取长宽,进行排版导出ezdxf 装箱算法 贪婪 总利用率91%
开发语言·python·excel
郏国上1 天前
遍历访问阿里云节点下的所有文件信息并写入excel文件
数据库·mongodb·阿里云·excel
mudtools1 天前
.NET驾驭Excel之力:Excel应用程序的创建与管理
c#·.net·excel·wps
mudtools1 天前
.NET驾驭Excel之力:自动化数据处理 - 开篇概述与环境准备
c#·自动化·.net·excel·wps