Ask Your Question

Finding Page Number where string exists [closed]

asked 2012-10-03 17:22:53 +0200

keavenen gravatar image

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.


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-18 15:50:14.810675


Answered my own question below

keavenen gravatar imagekeavenen ( 2012-10-17 14:47:18 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2012-10-17 14:46:47 +0200

keavenen gravatar image
    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(); 


    XInterface xfi = (XInterface) xSearchable.findFirst(xsd); 
    if (xfi != null) { 
        XTextRange xStart = ( UnoRuntime.queryInterface( 
      , xfi); 

        curTextView.gotoRange(xStart, false); 

    System.out.println("current page = " + curPage.getPage());
    return curPage.getPage();
edit flag offensive delete link more

Question Tools


Asked: 2012-10-03 17:22:53 +0200

Seen: 148 times

Last updated: Oct 17 '12