0

Following code is used:

public static void main(String[] args) throws IOException {
    FileInputStream is = new FileInputStream("C:/Users/hp/Downloads/sampPPT.ppt");

    HSLFSlideShow ppt = new HSLFSlideShow(is);
    is.close();
    Dimension pgsize = ppt.getPageSize();
    int idx = 1;
    for (HSLFSlide slide : ppt.getSlides()) {
        BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = img.createGraphics();
        // clear the drawing area
        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
        // render
        slide.draw(graphics);
        // save the output
        FileOutputStream out = new FileOutputStream("C:/Users/hp/Downloads/slide-" + idx + ".png");
        javax.imageio.ImageIO.write(img, "png", out);
        out.close();
        idx++;
    }

}

This throws following exception:

Exception in thread "main" java.lang.IllegalAccessError: class org.apache.poi.hslf.usermodel.HSLFSlideShowImpl tried to access private field org.apache.poi.POIDocument.directory (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl and org.apache.poi.POIDocument are in unnamed module of loader 'app')
    at org.apache.poi.hslf.usermodel.HSLFSlideShowImpl.readCurrentUserStream(HSLFSlideShowImpl.java:340)
    at org.apache.poi.hslf.usermodel.HSLFSlideShowImpl.<init>(HSLFSlideShowImpl.java:154)
    at org.apache.poi.hslf.usermodel.HSLFSlideShowImpl.<init>(HSLFSlideShowImpl.java:127)
    at org.apache.poi.hslf.usermodel.HSLFSlideShowImpl.<init>(HSLFSlideShowImpl.java:116)
    at org.apache.poi.hslf.usermodel.HSLFSlideShow.<init>(HSLFSlideShow.java:138)
    at PPTConv.PPTConv.main(PPTConv.java:27)
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • 1
    This kind of exception occur if you mix POI jars from different versions. This is not supported. See [FAQ](https://poi.apache.org/help/faq.html#faq-N10204). In your special case you probably have `poi-*.jar` and `poi-scratchpad-*.jar` from different versions in your classpath. I guess `poi-scratchpad-3.15.jar` together with `poi-3.16.jar` or later. – Axel Richter May 20 '20 at 08:40
  • Thanks.It helped me, my problem is resolved now. – Jagriti Pandey May 20 '20 at 09:20
  • Could you please help me with HWPF conversion into pdf with exact format ? As I am doing but it is extracting text only. – Jagriti Pandey May 20 '20 at 09:21
  • 1
    This would be a new question. But as far as I know, there is not any good `HWPF` to `PDF` converter until now. There is [XDocReport](https://github.com/opensagres/xdocreport). But this only has `XWPF` converter. And even this is very incomplete until now. – Axel Richter May 20 '20 at 10:26

1 Answers1

2

To make an answer why such exceptions occur. Maybe it is helpful for others too:

This kind of exception occur if you mix Apache POI jars from different versions. This is not supported. See FAQ.

In that special case there probably are poi-*.jar and poi-scratchpad-*.jar from different versions in classpath. The class org.apache.poi.hslf.usermodel.HSLFSlideShowImpl, which extends org.apache.poi.POIDocument, is contained in poi-scratchpad-*.jar while org.apache.poi.POIDocument is contained in poi-*.jar. If those *.jars are from different versions, then following can occur:

The org.apache.poi.hslf.usermodel.HSLFSlideShowImpl of poi-scratchpad-3.15.jar calls currentUser = new CurrentUserAtom(directory); in code line 340. This is possible because it extends org.apache.poi.POIDocument and this has field protected DirectoryNode directory; in version 3.15 (poi-3.15.jar).

But the same class org.apache.poi.POIDocument of version 3.16 (poi-3.16.jar) has field private DirectoryNode directory;. So if org.apache.poi.hslf.usermodel.HSLFSlideShowImpl of version 3.15 calls currentUser = new CurrentUserAtom(directory); in code line 340, but org.apache.poi.POIDocument is from version 3.16, then java.lang.IllegalAccessError: class org.apache.poi.hslf.usermodel.HSLFSlideShowImpl tried to access private field org.apache.poi.POIDocument.directory is thrown because it really tries to access a private field now.

Axel Richter
  • 56,077
  • 6
  • 60
  • 87