2

I'm writing a little tool that converts slides in PPT Files to pngs, the problem I'm having is with hidden slides. How can I change a slide to be visible in java? Im currently using Apache POI for conversion to PNGs, although this doesn't work for clipart so I am tempted with exporting it to a PDF using unoconv first, then minipulating that. But doing it like this doesn't take in to account all the hidden slides. So how could I programmatically change the hidden slides to be visible?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dean
  • 8,668
  • 17
  • 57
  • 86
  • Each slide has a .SlideShowTransition.Hidden property (Boolean) that governs whether it's hidden or not. – Steve Rindsberg Dec 17 '12 at 23:56
  • @SteveRindsberg Where is this method? – Dean Dec 18 '12 at 00:32
  • It's part of the PowerPoint object model. Whether POI and Java give you access to that or not, I don't know. If you have access to the XML in the PPTX file, the slidenn.xml file will begin with something like: if the slide's hidden. Unhidden slides will not have the show="0" part. – Steve Rindsberg Dec 18 '12 at 20:31

1 Answers1

2

This is kind of a hack and has been tested only with a PPT from Libre Office with POI 3.9 / POI-Scratchpad 3.8.

The spec ([MS-PPT].pdf / version 3.0 / page 201) says, that Bit 3 (fHidden) of Byte 18 specifies whether the corresponding slide is hidden and is not displayed during the slide show

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Field;

import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.UnknownRecordPlaceholder;
import org.apache.poi.hslf.usermodel.SlideShow;

public class UnhidePpt {
    public static void main(String[] args) throws Exception {
        FileInputStream fis = new FileInputStream("hiddenslide.ppt");
        SlideShow ppt = new SlideShow(fis);
        fis.close();

        Field f = UnknownRecordPlaceholder.class.getDeclaredField("_contents");
        f.setAccessible(true);


        for (Slide slide : ppt.getSlides()) {
            for (Record record : slide.getSlideRecord().getChildRecords()) {
                if (record instanceof UnknownRecordPlaceholder
                    && record.getRecordType() == RecordTypes.SSSlideInfoAtom.typeID) {
                    UnknownRecordPlaceholder urp = (UnknownRecordPlaceholder)record;

                    byte contents[] = (byte[])f.get(urp);
                    contents[18] &= (255-4);
                    f.set(urp, contents);
                }
            }
        }

        FileOutputStream fos = new FileOutputStream("unhidden.ppt");
        ppt.write(fos);
        fos.close();
    }
}
kiwiwings
  • 3,386
  • 1
  • 21
  • 57
  • I've submitted a [patch #55560](https://issues.apache.org/bugzilla/show_bug.cgi?id=55560). Lets see when it gets integrated ... – kiwiwings Sep 15 '13 at 23:04