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();
        }
    }
}
相关推荐
统计学小王子1 小时前
数学建模国赛倒计时8天——《搭建建模Word框架(字体字号)》
数学建模·word
一晌小贪欢5 小时前
python-第15天:Python 列表推导式
开发语言·python·excel·数据可视化·python办公
tryxr9 小时前
Chat2Excel 项目通用服务开发
java·开发语言·excel·java项目开发
Jazz_z9 小时前
使用 Python 合并与取消合并 Excel 单元格
开发语言·python·excel
2601_962381862 天前
Python办公联动:Excel数据一键自动生成PPT图表
python·数据分析·自动化·excel·ppt
EXI-小洲3 天前
Java 操作 Word:字符串替换、图片插入、动态生成表格与API接口下载
java·开发语言·spring boot·word
三声三视3 天前
Word 转 Markdown 报“保真率 98%“,可那张表散了
word·word转markdown·格式转换·开发者工具·tri-docx2md·结构保真
tryCbest3 天前
Excel常用公式(WPS vs Office)
excel·wps
课件帮3 天前
从Word教案到带讲解微课:课件帮一键成片全流程实操
word
taller_20003 天前
【006】何时用 Python?何时用 Excel 公式?一文讲清
python·excel·公式·pie·py