开发者社区> 问答> 正文

jacob操作ppt报错?报错

private boolean ppt2PDF(String inputFile, String pdfFile) {
        ComThread.InitSTA();

        long start = System.currentTimeMillis();
        ActiveXComponent app = null;
        Dispatch ppt = null;
        try {
            app = new ActiveXComponent("PowerPoint.Application");// 创建一个PPT对象
            //app.setProperty("Visible", new Variant(true)); // 不可见打开(PPT转换不运行隐藏,所以这里要注释掉)
            //app.setProperty("AutomationSecurity", new Variant(3)); // 禁用宏
            Dispatch ppts = app.getProperty("Presentations").toDispatch();// 获取文挡属性

            System.out.println("打开文档 >>> " + inputFile);
            // 调用Documents对象中Open方法打开文档,并返回打开的文档对象Document
            ppt = Dispatch.call(ppts, "Open", inputFile, 
                    true,// ReadOnly
                    true,// Untitled指定文件是否有标题
                    false// WithWindow指定文件是否可见
                    ).toDispatch();
            
            System.out.println("转换文档 [" + inputFile + "] >>> [" + pdfFile + "]");
            Dispatch.call(ppt, "SaveCopyAs", pdfFile, ppFormatPDF);
            //Dispatch.call(ppt, "ExportAsFixedFormat", pdfFile, ppFormatPDF);
            long end = System.currentTimeMillis();

            System.out.println("用时:" + (end - start) + "ms.");

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("========Error:文档转换失败:" + e.getMessage());
        } finally {
            Dispatch.call(ppt, "Close");
            System.out.println("关闭文档");
            if (app != null)
                app.invoke("Quit", new Variant[] {});
        }
        ComThread.Release();
        ComThread.quitMainSTA();
        return false;
    }

就是网上到处流传的这段代码,PPT转pdf就会报错

com.jacob.com.ComFailException: Invoke of: SaveAs
Source: Microsoft PowerPoint 2013
Description: Presentation.SaveAs : PowerPoint 无法将 ^0 保存到 ^1。

PPT转jpg也是这样的错误,但是word和excel就不会,求解啊,,,

或者有什么其它的windows下office转pdf的方法么(⊙v⊙)?

跪谢。

展开
收起
爱吃鱼的程序员 2020-06-09 13:50:08 712 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    openoffice调用服务转换,不用msoffice,具体可百度。

    2020-06-09 13:50:26
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
成功案例-Par...[幸运杰哥].1512720360.pdf 立即下载
《新服务(第三期)》PDF 立即下载
5日docker训练营(一).ppt 立即下载