this is my first post. If this is not the appropriate section, please move this post.
I am trying to build OpenOffice Draw files from Java. I need to insert images without file (because rendered at runtime in a BufferedImage). Is there a way to circumvent writing the png temporarily to disk, inserting that file into Draw, unlinking the link and then remove the temporary file? I could not find any XNameContainer.insertByName alternative to do this or to build an url that is not pointing to a file.
Code in question:
Code: Select all
BufferedImage img;
//img is rendered at runtime
//and needs to be saved to a file to give this filename as reference later on
//for example:
ImageIO.write(img, "png", new File("/home/me/tmpfile.png")); //I would like to circumvent this step
//OO Uno
XComponentContext context = Bootstrap.bootstrap();
XMultiComponentFactory mcf = context.getServiceManager();
Object desktop = mcf.createInstanceWithContext("com.sun.star.frame.Desktop", context);
XComponentLoader componentLdr = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
XComponent xDrawComponent = componentLdr.loadComponentFromURL("private:factory/sdraw", "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawComponent);
Object drawPages = xDrawPagesSupplier.getDrawPages();
XIndexAccess xIndexedDrawPages = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, drawPages);
Object drawPage = xIndexedDrawPages.getByIndex(0);
XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, drawPage);
XMultiServiceFactory xDrawFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawComponent);
Object shape = xDrawFactory.createInstance("com.sun.star.drawing.GraphicObjectShape");
XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, shape);
xShape.setSize(new Size(6050, 3000));
xShape.setPosition(new Point(2000, 1000));
XNameContainer bitmapContainer = UnoRuntime.queryInterface(XNameContainer.class,
xDrawFactory.createInstance("com.sun.star.drawing.BitmapTable"));
bitmapContainer.insertByName("testimg", "file:///home/me/tmpfile.png"); //what to do here to insert img directly instead of tmpfile.png?
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, shape);
Object url = bitmapContainer.getByName("testimg");
xPropSet.setPropertyValue("GraphicURL", url);
xDrawPage.add(xShape);
//temp-file is not used anymore and could be deleted