gshklover wrote:Anybody knows how exactly this should work with JavaScript?
Intriguing question! I gave it a try but sadly to no avail.
Using the JavaScript examples delivered with OOo/LO I wrote this JavaScript macro:
Code: Select all
// Import standard OpenOffice.org API classes. For more information on
// these classes and the OpenOffice.org API, see the OpenOffice.org
// Developers Guide at:
// http://api.openoffice.org/
importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.text.XTextDocument);
importClass(Packages.com.sun.star.text.XText);
importClass(Packages.com.sun.star.text.XTextRange);
importClass(Packages.com.sun.star.frame.XModel);
importClass(Packages.com.sun.star.frame.XStorable);
importClass(Packages.com.sun.star.beans.PropertyValue);
//get the document object from the scripting context
oDoc = XSCRIPTCONTEXT.getDocument();
//get the XTextDocument interface
xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
//get the XModel interface from the document
xModel = UnoRuntime.queryInterface(XModel,oDoc);
//get the XStorable interface used to save the document
xStorable = UnoRuntime.queryInterface(XStorable,xTextDoc);
//set up an array of PropertyValue objects used to set the filter settings
filterProps = new Array();
filterProps[0] = new PropertyValue();
filterProps[0].Name = "PermissionPassword";
filterProps[0].Value = "nopermission";
filterProps[1] = new PropertyValue();
filterProps[1].Name = "UseLosslessCompression";
filterProps[1].Value = true;
filterProps[2] = new PropertyValue();
filterProps[2].Name = "SelectPdfVersion";
filterProps[2].Value = 1;
filterProps[3] = new PropertyValue();
filterProps[3].Name = "Magnification";
filterProps[3].Value = 4;
filterProps[4] = new PropertyValue();
filterProps[4].Name = "Zoom";
filterProps[4].Value = 250;
//set up an array of PropertyValue objects used to save the document
storeProps = new Array();
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "writer_pdf_Export";
storeProps[1] = new PropertyValue();
storeProps[1].Name = "Overwrite ";
storeProps[1].Value = true;
storeProps[2] = new PropertyValue();
storeProps[2].Name = "FilterData";
storeProps[2].Value = filterProps;
storeUrl = xModel.getURL();
storeUrl = storeUrl.substring(0,storeUrl.lastIndexOf('.'));
xStorable.storeToURL(storeUrl+".pdf", storeProps);
Intriguingly I don't get any errors, but the last line just does nothing. No error, no exception, no result, nothing.
What does work is this example using no FilterData at all:
Code: Select all
// Import standard OpenOffice.org API classes. For more information on
// these classes and the OpenOffice.org API, see the OpenOffice.org
// Developers Guide at:
// http://api.openoffice.org/
importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.text.XTextDocument);
importClass(Packages.com.sun.star.text.XText);
importClass(Packages.com.sun.star.text.XTextRange);
importClass(Packages.com.sun.star.frame.XModel);
importClass(Packages.com.sun.star.frame.XStorable);
importClass(Packages.com.sun.star.beans.PropertyValue);
//get the document object from the scripting context
oDoc = XSCRIPTCONTEXT.getDocument();
//get the XTextDocument interface
xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
//get the XModel interface from the document
xModel = UnoRuntime.queryInterface(XModel,oDoc);
//get the XStorable interface used to save the document
xStorable = UnoRuntime.queryInterface(XStorable,xTextDoc);
//set up an array of PropertyValue objects used to save the document
storeProps = new Array();
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "writer_pdf_Export";
storeProps[1] = new PropertyValue();
storeProps[1].Name = "Overwrite ";
storeProps[1].Value = true;
storeUrl = xModel.getURL();
storeUrl = storeUrl.substring(0,storeUrl.lastIndexOf('.'));
xStorable.storeToURL(storeUrl+".pdf", storeProps);
Although this works from a Writer document which has previously been saved, I know, this was not the question of this thread.
I tried both JavaScript macros with OOo 3.2.0 and LO 3.3.1 on Ubuntu 10.04. The first macro did not work at all, the second worked with OOo 3.2.0 and LO 3.3.1.