First time here? Check out the FAQ!
I'm looking for an Uno call or javascript call to find the page number that a certain string is on.
I have javascript to search the document and locate the string but then I need someway to determine the page number that string is on.
then I can print this page from a different tray.
thanks
public int searchPageNumber()
{
XController xController = OODocument.getCurrentDocument().getXFrame().getController();
XTextViewCursorSupplier supTextViewCursor =
(XTextViewCursorSupplier) UnoRuntime.queryInterface(
XTextViewCursorSupplier.class, xController);
XTextViewCursor curTextView = supTextViewCursor.getViewCursor();
// gets the page cursor and assigns the text view cursor to the page
XPageCursor curPage =
(XPageCursor) UnoRuntime.queryInterface(
XPageCursor.class, curTextView);
System.out.println("The current page number is " + curPage.getPage());
// gets the model
XModel model = xController.getModel();
// assigns model to the document
XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, model);
// Xsearchable so we can search the text
XSearchable xSearchable = (XSearchable) UnoRuntime.queryInterface(XSearchable.class, xTextDocument);
XSearchDescriptor xsd = (XSearchDescriptor) xSearchable.createSearchDescriptor();
xsd.setSearchString("zzzzz");
XInterface xfi = (XInterface) xSearchable.findFirst(xsd);
if (xfi != null) {
XTextRange xStart = (com.sun.star.text.XTextRange) UnoRuntime.queryInterface(
com.sun.star.text.XTextRange.class, xfi);
curTextView.gotoRange(xStart, false);
}
System.out.println("current page = " + curPage.getPage());
return curPage.getPage();
}
LibreOffice is made available by volunteers around the globe, backed by a charitable Foundation. Please support our efforts: Your donation helps us to deliver a better product!
Asked: 2012-10-03 17:22:53 +0200
Seen: 54 times
Last updated: Oct 17 '12
Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
Answered my own question below
keavenen ( 2012-10-17 14:47:18 +0200 )edit