 | OO-Snippets: print previewCommons| Keywords | print preview |
|---|
| Language | Java |
|---|
| Application | Office |
|---|
| Authors | Tom Schindl (initial)
Stephan Wunderlich (initial)
|
|---|
| Supported Versions | |
|---|
| Supported OS | |
|---|
| Question |
How to get a print preview
I've been looking at printing via the OpenOffice.org API. Is there a way to get a print preview? There doesn't seem to be anything about this in the Devlopers' Guide.
|
|---|
| Answer | supposing you have the XModel (xModel) of the document and the ServiceManager (xMSF) then the following should do what you want. |
|---|
import com.sun.star.frame.XController;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XModel;
import com.sun.star.util.XURLTransformer;
import com.sun.star.util.URL;
import com.sun.star.lang.XMultiServiceFactory;
XController xController = xModel.getCurrentController();
try {
XDispatchProvider xDispProv = (XDispatchProvider)
UnoRuntime.queryInterface(XDispatchProvider.class, xController);
XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
UnoRuntime.queryInterface(XURLTransformer.class,
xMSF.createInstance("com.sun.star.util.URLTransformer"));
URL[] aParseURL = new URL[1];
aParseURL[0] = new URL();
aParseURL[0].Complete = ".uno:PrintPreview";
xParser.parseStrict(aParseURL);
URL aURL = aParseURL[0];
XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
if(xDispatcher != null) {
xDispatcher.dispatch( aURL, new PropertyValue[]{} );
}
} catch (com.sun.star.uno.Exception e) {
}
|
Changelog| Date | User | Modification |
|---|
| 2004-11-18 | tomsontom | Initial version, summed up from mailling list | | 2004-11-18 | tomsontom | Added missing imports |
|