apiopenoffice.orgopenoffice-impress

OpenOffice Drawing API: Create slideshow from page-sized pictures


I create an Impress presentation from a series of image files. I can create a Page and insert the GraphicObjectShape without any problem, but got stuck when I have to size the shape containing the image.

My problem is that I have no clue what sizes should I use. Of course I could go with a trial and error process, but it would not be very professional would it?

My questions: what is the size of the new Page I create in pixels? How to access the function "Original Size" which can be found in the picture's context menu?

In the Page Setup I see a size of 11.02" x 8.27" - Is there any guarantee that all future versions will use this size when I create a new document and a new page within?

It would be interesting to know what size the image file should be to fit the whole page.


Solution

  • It seems that raster images are loaded with a 96 DPI resolution. If you are using the default page size for Impress (11.02" x 8.27") then the fully fitting raster image size (in pixels) is:

    1058 x 794

    Also, if you stick with this size (as it is probably the most compatible choice for example when you are saving to PPT), do not rely on the fact that this is the default. After document is created you can set the size of the slides by setting the Width and Height property of any page (it seems that all other pages going to follow after you resize one of them).

    The API uses a 100/mm scale. 11.02 iches are 280 mm, so width is 280 * 100 = 28000, height is 21000.

    Java example to resize the presentaion to 11.02" x 8.27" and insert (a preferably 4:3) image to fit the whole page:

    XDrawPage page;
    XMultiServiceFactory factory;
    
    // ... setting up the environment and opening document
    
    // resize the page (and all other pages) to our default size
    XPropertySet pagePropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, page);
    pagePropSet.setPropertyValue("Width", 28000);
    pagePropSet.setPropertyValue("Height", 21000);
    
    // create GraphicObjectShape with the size of the page in the top-left corner
    Object picture = factory.createInstance("com.sun.star.drawing.GraphicObjectShape");
    XShape pictureShape = (XShape)UnoRuntime.queryInterface(XShape.class, picture);
    pictureShape.setSize(new Size(28000, 21000));
    pictureShape.setPosition(new Point(0, 0));
    
    // load the image file into our the shape
    XPropertySet propSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, pictureShape);
    propSet.setPropertyValue("GraphicURL", new File("c:\\Users\\Vbence\\Downloads\\slide.png").toURI().toURL().toString());
    
    // add the shape to the page
    page.add(pictureShape);