[Solved] Using java-UNO to insert slide

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
victor_charlie
Posts: 1
Joined: Thu Aug 23, 2012 2:44 am
Location: Texas Hill Country

[Solved] Using java-UNO to insert slide

Post by victor_charlie »

Can anyone point me to, or provide a snippet, of obtaining the Impress Object and inserting a slide in Java? I have googled for a while trying to get a handle on the API. Unfortunate software names blocks me from getting results, e.g. 'uno java impress' gets me Italian / Spanish hits using javascript -> opción número uno.



edit:::::::::::::
Thanks FJCC! I tried to make-build a similar tool written in Java that (sadly) was overly complicated. The Python tool MRI was exactly what I needed.
Last edited by victor_charlie on Thu Aug 23, 2012 3:50 pm, edited 1 time in total.
LibreOffice 3.4.4 / OOO340m1(Build:402) on AMD64 Ubuntu 11.10
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Using java-UNO to insert slide

Post by FJCC »

You can save yourself innumerable hours by getting an object inspector like MRI. I used it to record this Java code to add a slide to an existing presentation. oInitialTarget is the document.

Code: Select all

import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.uno.UnoRuntime;

static public void snippet(Object oInitialTarget)
{
	XDrawPagesSupplier xDrawPagesSupplier = UnoRuntime.queryInterface(
		XDrawPagesSupplier.class, oInitialTarget);
	XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
	
	XDrawPage xDrawPage = xDrawPages.insertNewByIndex(1);
	
}
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
jza
Posts: 239
Joined: Mon Nov 03, 2008 11:33 am
Location: Cancún, Mexico

Re: [Solved] Using java-UNO to insert slide

Post by jza »

Have you seen the developer guide, most of its snippets are in Java and also is divided by Modules, impress is a bit odd, since both impress and draw are builted under the same basic object.
Image

The XDawPages is the right supplier to insert new pages. including the method pointed by FJCC insertNewByIndex() under DrawingMasterPages
AOO 4.1.1 on Arch Linux
Post Reply