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();
        }
    }
}
相关推荐
小e说说2 小时前
2026 最强PPT制作工具大盘点,全类型覆盖,建议收藏
powerpoint
asdzx672 小时前
使用 C# 从 URL 下载 Word 文档
开发语言·c#·word
小t说说2 小时前
6款实用PPT生成工具
powerpoint
z19408920664 小时前
在线题库整理:把重复劳动从 Excel 手工里解放出来
excel
小e说说5 小时前
吐血实测!十款PPT生成工具大PK,谁才是效率之王?
powerpoint
开开心心_Every5 小时前
免费简洁的安卓黄历日历,软件推荐
运维·服务器·随机森林·pdf·电脑·excel·最小二乘法
VBAMatrix19 小时前
deepseek-v4正式接入Excel,一键生成财务分析报告
word·excel·审计·财务分析·deepseek·会计师事务所·tb工具箱
thethefighter1 天前
免安装在信创环境中使用word文档查看预览工具
word·信创·预览·银河麒麟·免安装·绿色·word预览工具
开开心心就好1 天前
自动分类存储PPT素材的实用工具
科技·游戏·智能手机·电脑·powerpoint·sublime text·phpstorm
aisifang001 天前
PDF转Word神器:Gemini3.1Pro一键搞定文档处理
人工智能·pdf·word