5

I'm building a Java aplication using the OOo SDK where I'm manipulating slides in an OpenOffice Impress presentation. I know how to get an object containing a single slide, now I'm looking for a way to copy a slide from a presentation to another.

That's (shortened) what I do to open the files and selecting the slide:

String filename = "file://....odp";
int offset = 2;

XComponent xSourceComponent = xComponentLoader.loadComponentFromURL(filename, "_blank", 0, loadProps);
XComponent xTargetComponent = xComponentLoader.loadComponentFromURL("private:factory/simpress", "_blank", 0, loadProps);

XDrawPages xDrawPages = ((XDrawPagesSupplier)UnoRuntime.queryInterface(
         XDrawPagesSupplier.class, xSourceComponent)).getDrawPages();

XPresentationPage xPage = (XPresentationPage)UnoRuntime.queryInterface(XPresentationPage.class,
         xDrawPages.getByIndex(offset));

Based on I tried to get a transferable object like this:

XTransferable t = (XTransferable)UnoRuntime.queryInterface(
         XTransferable.class, xPage);

But that doesn't seem to be supported. Anybody has an idea how to do this?

Grzegorz Oledzki
  • 23,614
  • 16
  • 68
  • 106
johannes
  • 15,807
  • 3
  • 44
  • 57

1 Answers1

1

Oh man, good luck. I looked at trying to do something like this about a year ago and ended up using Apache POI instead -- not necessarily sure the OO SDK can't do this, but the documentation for the API is so esoteric that I couldn't figure it out. In POI it's as easy as

SlideShow ss1 = new SlideShow(new FileInputStream(inputFile1));
Slide newSlide = ss.createSlide();
for (Shape shape : ss.getSlides()[0].getShapes()) {
    newSlide.addShape(shape);
}

That may not really help you since you're dealing with OO not PPT, but if you're desperate for a solution and not getting help on the OpenOffice front, you could probably string together JODConverter (http://www.artofsolving.com/opensource/jodconverter) and POI.

jkraybill
  • 3,339
  • 27
  • 32
  • Indeed, the documentation is not easy usable. The aim is to have a wizard as plugin in OOo which creates and fills out some slides so I'm bound to OOs's UNO APIs. Most stuff is working but currently the layout of the created slides is defined in code I'd like to have a template a user can edit. – johannes May 09 '11 at 07:39
  • Have you taken a look at ODFDOM? It looks like it has a slide copy operation in it (OdfPresentationDocument.copyForeignSlide). – jkraybill May 10 '11 at 00:00