如何在Java Applet中显示PPT文件?

时间:2010-03-14 15:26:38

标签: java applet ms-office powerpoint

我想在Java Applet中打开并显示现有的Microsoft PowerPoint演示文稿。我怎么能这样做?

3 个答案:

答案 0 :(得分:2)

Tonic Systems was selling一个Java PPT渲染器,直到它们为bought by Google。我知道没有其他解决方案。

当然,你可以自己实现这个,但这将是很多工作。在Apache POI项目中读取和编写PPT文件有基本的支持,但您必须自己完成所有渲染。

答案 1 :(得分:1)

可视化可以通过将每个幻灯片可视化为jpg图像来完成。 您可以使用Jacob java库进行转换。此库演示COM桥并获取Microsoft Office Power Point进行转换(通过save-as命令)。我有PP2007:

package jacobSample;
import com.jacob.activeX.*;
import com.jacob.com.*;

public class Ppt {
ActiveXComponent pptapp = null;  //PowerPoint.Application ActiveXControl Object
  Object ppto = null;  //PowerPoint.Application COM Automation Object
  Object ppts = null;  //Presentations Set
  // Office.MsoTriState
  public static final int msoTrue = -1;
  public static final int msoFalse = 0;
  // PpSaveAsFileType
  public static final int ppSaveAsJPG = 17 ;


  //other formats..
  public static final int ppSaveAsHTML = 12;
  public static final int ppSaveAsHTMLv3 =13;
  public static final int ppSaveAsHTMLDual= 14;
  public static final int ppSaveAsMetaFile =15;
  public static final int ppSaveAsGIF =16;
  public static final int ppSaveAsPNG =18;
  public static final int ppSaveAsBMP =19;
  public static final int ppSaveAsWebArchive =20;
  public static final int ppSaveAsTIF= 21;
  public static final int ppSaveAsPresForReview= 22;
  public static final int ppSaveAsEMF= 23;

  public Ppt(){
    try{
         pptapp = new ActiveXComponent("PowerPoint.Application");
      ppto = pptapp.getObject();

      ppts = Dispatch.get((Dispatch)ppto, "Presentations").toDispatch();

    }catch(Exception e){
      e.printStackTrace();
    }
  }
  public Dispatch getPresentation(String fileName){
    Dispatch pres = null; //Presentation Object
    try{
      pres = Dispatch.call((Dispatch)ppts, "Open", fileName,
        new Variant(Ppt.msoTrue), new Variant(Ppt.msoTrue),
        new Variant(Ppt.msoFalse)).toDispatch();
    }catch(Exception e){
      e.printStackTrace();
    }
    return pres;
  }
  public void saveAs(Dispatch presentation, String saveTo, int ppSaveAsFileType){
    try{
      Object slides = Dispatch.get(presentation, "Slides").toDispatch();
      Dispatch.call(presentation, "SaveAs", saveTo, new Variant(ppSaveAsFileType));
    }catch (Exception e) {
      e.printStackTrace();
    }

  }
  public void closePresentation(Dispatch presentation){
      if(presentation != null){
      Dispatch.call(presentation, "Close");
    }
  }
  public void quit(){
      if(pptapp != null){
      ComThread.Release();

      //pptapp.release();
      try{
      pptapp.invoke("Quit", new Variant[]{});
      }catch(Exception e){
          System.out.println("error");
      }
    }
  }
  public static void main(String[] args){
      //System.loadLibrary("jacob-1.15-M4-x86.dll");
      //System.loadLibrary("jacob-1.15-M4-x64.dll");

    Ppt a = new Ppt();
    System.out.println("start");
    Dispatch pres = a.getPresentation("C:\\j.pptx");// pptx file path 


    a.saveAs(pres, "C:\\im", Ppt.ppSaveAsJPG); // jpg destination folder

    a.closePresentation(pres);
    a.quit();
    System.out.println("end");
  }
 }

答案 2 :(得分:0)

我不确定我的模拟PPT渲染的想法是否有效:

  1. 让服务器端读取PPT文件并生成JPG文件以供显示。
  2. 浏览器端将使用ajax从PPT请求任何特定页面。