Required jar: jackrabbit-standalone-1.5.0.jar


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.usermodel.PictureData;
import org.apache.poi.hslf.usermodel.SlideShow;

public class PPttoimg {

/**
* @param args
*/
public static void main(String[] args) {
SlideShow ppt = null;
try {
ppt = new SlideShow(new HSLFSlideShow("Screenshot.ppt"));
} catch (IOException e) {

e.printStackTrace();
}

//extract all pictures contained in the presentation
PictureData[] pdata = ppt.getPictureData();
for (int i = 0; i < pdata.length; i++){
PictureData pict = pdata[i];

// picture data
byte[] data = pict.getData();

int type = pict.getType();
String ext;
switch (type){
case Picture.JPEG: ext=".jpg"; break;
case Picture.PNG: ext=".png"; break;
case Picture.WMF: ext=".wmf"; break;
case Picture.EMF: ext=".emf"; break;
case Picture.PICT: ext=".pict"; break;
default: continue;
}
FileOutputStream out;
try {
out = new FileOutputStream("pict_"+i + ext);
out.write(data);
out.close();
} catch (FileNotFoundException e) {

e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
}

}

}

}

Check Point:

Advertisements

Comments on: "Extract all pictures contained in the presentation to image convertion java code" (21)

  1. I have try to make this programme but i can, first i have download the other jars and then i have compiled ths programme,without fails but there i didn’t have any idea for where did i put the ppt file and how we can make the pic ?
    thanks again

    • Hi Amine,

      ppt = new SlideShow(new HSLFSlideShow(“Screenshot.ppt”));

      Instead of Screenshot.ppt name give the full file path name of yours ppt file.
      For ex : ppt = new SlideShow(new HSLFSlideShow(“c:\\foldername\filename.ppt”));

      Thanks & Regards
      Rajeeva Lochana.B.R

      • AMINE said:

        Hi it’s me again

        I try many times to make it run but i can’t
        i have put a slide.ppt in “c:\\file\\” and i have download all the jars but without any result

        And that's the errors :

        Exception in thread "main" java.lang.NoSuchMethodError:
        org.apache.poi.poifs.filesystem.POIFSFileSystem.
        getRoot()Lorg/apache/poi/poifs/filesystem/DirectoryNode;
        at org.apache.poi.hslf.HSLFSlideShow.(HSLFSlideShow.java:115)
        at org.apache.poi.hslf.HSLFSlideShow.(HSLFSlideShow.java:103)
        at org.apache.poi.hslf.HSLFSlideShow.(HSLFSlideShow.java:91)
        at PPttoimg.main(PPttoimg.java:17)

  2. AMINE said:

    those are the jars that i have used :

    aspose.slides-2.6.0.jar
    batik-all-1.8pre-r1084380.jar
    batik-slideshow.jar
    jackrabbit-standalone-1.5.0.jar
    jakarta-poi-2.5.jar
    jakarta-slide-webdavlib-2.1.jar
    jodconverter-2.1.1.jar
    openoffice-juh-2.0.3.jar
    openoffice-ridl-3.1.0.jar
    poi-3.2-FINAL.jar
    poi-3.5-beta1.jar
    poi-scratchpad-3.5-beta5-20090219.jar
    unoil-3.0.0.jar
    ws4d-dpws-stack.presentation.jar

    else please tell me the right jars.

    Have a nice day.

    • Hi Amine,

      Sorry for the delay
      “jackrabbit-standalone-1.5.0.jar” jar is enough.
      don’t forget to remove all other jar from your reference/lib folder.

      If u have any query please let me know.

      Thanks,
      Rajeeva Lochana.B.R

  3. where i can download the jackrabbit-standalone-1.5.0.jar, the link is broken here

  4. kummu said:

    hi ,

    where the images will be saved ?

  5. Finley said:

    hi
    Where can I see the pictures after conversion?
    Thanks.

  6. it is extracting all the images from ppt but i want to convert each slides as a image like (png or jpg)with out using java awt and image io library pls reply soon

    Thank You

  7. One more thing: I tried ur code. Looks like everything thing is working fine but not able to find the output images. I manually created the lib folder in my project.

    • Hi Mrana,

      Sorry for the late replay,

      It is not an issue. We need to create manually the Lib folder. Regarding the output result, check the path which you have mentioned here
      out = new FileOutputStream(“pict_”+ i + ext);“.
      If you are using the same code then you can get the result image in the porject folder itself, after running the application refresh the page.

      If you have any concern let me know.

  8. I tried the above link for ppt to pdf conversion but getting errors in connection from their side.Its not listening to any request. So could u suggest any other way of converting the ppt/x,doc/x into pdf.

  9. rathan said:

    I am getting null value ( PictureData[] pdata ) for pdata,

    i.e ppt.getPicturedata(); returning null value.

    Because of null values i am getting null pointer Exception in console and program

    terminated abnormally

    please share answer for this query

    • Hi Rathan

      Check configured file is existing on the same path or not. You will get the Null pointer exception when file is not exist on the specific path.

      Please let me know if you have any concern.

      • rathan said:

        Hi Rajeeva
        which configure file

      • rathan said:

        Hi Rajeeva
        the Code is
        ppt = new SlideShow(new HSLFSlideShow(“D:\\ab.ppt”));

        ab.ppt is ppt file name
        and present in d : directory

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: