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();
        }
    }
}
相关推荐
DS随心转插件5 小时前
AI导出鸭:DeepSeek 转 Word 效果实测与案例展示
人工智能·ai·word·豆包·deepseek·ai导出鸭
技术小甜甜7 小时前
[办公效率] Excel 表格越做越乱,先整理字段、格式还是公式?
数据库·excel·办公效率·数据整理
SunnyDays10118 小时前
如何使用 C# 自动调整 Excel 行高和列宽
开发语言·c#·excel
itgather9 小时前
OfficeExcel — Word / Excel DLL 验证台功能介绍
c#·word·excel
葡萄城技术团队9 小时前
【SpreadJS 新版本特性揭秘】完美对齐 Excel 365:V19.1 单元格内嵌图片架构解析
excel
qq_422152579 小时前
Excel 转 CSV 工具怎么选?格式兼容、编码问题与数据导出方案实测
excel
҉人间无事人9 小时前
wps中excel跨表通过匹配数据取其他值
excel·wps
sbjdhjd9 小时前
04 (下) | K8S微服务实战:从 Service 到金丝雀发布
运维·微服务·云原生·kubernetes·开源·云计算·excel
DS随心转插件10 小时前
AI导出鸭深度评测:DeepSeek 转 Word 实战表现与边界分析
人工智能·ai·word·文心一言·deepseek·ai导出鸭
qq_422152571 天前
PDF 转 Word 哪个工具好用?2026 年主流方案对比与选型指南
pdf·word