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();
        }
    }
}
相关推荐
玩泥巴的15 小时前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
word·二次开发·office·com互操作
QQ3596773451 天前
ArcGIS Pro实现基于 Excel 表格批量创建标准地理数据库(GDB)——高效数据库建库解决方案
数据库·arcgis·excel
玩泥巴的2 天前
.NET驾驭Word之力:COM组件二次开发全攻略之连接Word与创建你的第一个自动化文档
word·二次开发·com互操作
星空的资源小屋2 天前
Digital Clock 4,一款免费的个性化桌面数字时钟
stm32·单片机·嵌入式硬件·电脑·excel
揭老师高效办公3 天前
在Excel和WPS表格中批量删除数据区域的批注
excel·wps表格
我是zxb3 天前
EasyExcel:快速读写Excel的工具类
数据库·oracle·excel
辣香牛肉面3 天前
[Windows] 搜索文本2.6.2(从word、wps、excel、pdf和txt文件中查找文本的工具)
word·excel·wps·搜索文本
yzx9910133 天前
豆包、Kimi、通义千问、DeepSeek、Gamma、墨刀 AI”六款主流大模型(或 AI 平台)生成 PPT 的完整流程
人工智能·powerpoint·墨刀
ljf88383 天前
Java导出复杂excel,自定义excel导出
java·开发语言·excel
tebukaopu1483 天前
json文件转excel
json·excel