How can I display a PPT file in a Java applet?

I want to open and display an existing Microsoft PowerPoint presentation in a Java applet. How can i do this?

+3
source share
3 answers

Tonic Systems sold the Java PPT renderer until they were acquired by Google . I do not know another solution.

Of course, you can implement it yourself, but it will be a lot of work. There is rudimentary support for reading and writing PPT files in the Apache POI project , but you will have to do all the rendering yourself.

+2
source

jpg-. java- Jacob . 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");
  }
 }
+1

I'm not sure if my idea of ​​simulating PPT rendering works:

  • Let the back end read the PPT file and create the jpg files for display.
  • The browser side will use ajax to request any particular page from the PPT.
0
source

Source: https://habr.com/ru/post/1736889/


All Articles