I want to count the no. of pages that would be produced if I printed out an OpenOffice.org document. I can already do it for ODT files using the following code:
public short getPageCount() {
XModel model = (XModel) UnoRuntime.queryInterface(XModel.class,
getDocument());
XTextViewCursorSupplier supplier = (XTextViewCursorSupplier) UnoRuntime
.queryInterface(XTextViewCursorSupplier.class, model
.getCurrentController());
XTextViewCursor viewCursor = supplier.getViewCursor();
XPageCursor pageCursor = (XPageCursor) UnoRuntime.queryInterface(
XPageCursor.class, viewCursor);
pageCursor.jumpToLastPage();
return pageCursor.getPage();
}
public Object getDocument() {
XComponentContext context = Bootstrap.bootstrap();
XMultiComponentFactory factory = context.getServiceManager();
Object desktop = factory.createInstanceWithContext(
"com.sun.star.frame.Desktop", context);
XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface(
XComponentLoader.class, desktop);
XComponent component = loader.loadComponentFromURL("file:///path/to/file.odt",
"_blank", 0, new PropertyValue[0]);
return UnoRuntime.queryInterface(XTextDocument.class,
component);
}
I want to know if I can do something similar with ODS files. Maybe count the no. of page breaks in the sheets? There is a ShowPageBreaks property in the SpreadsheetViewSettings class but no PageBreakCount or getPageBreaks(). :P