Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:06:12+00:00 2026-06-13T01:06:12+00:00

I have the below code which returns the total number of pages in my

  • 0

I have the below code which returns the total number of pages in my document. I can call this with javascript soapplet.getNumberOfPages()

I want to do a similar method that will return just the PageNumber. I have found this class com.sun.star.text.TextField.PageNumber but I cannot figure out how to return a string of the PageNumber. In javascript then I will be able to search the document for a certain string and depending where the string is found I will be able to determine the page number on that document where string exists. I can then tell the printer to print this page from the headed paper tray. I’ve googled for a day or two and can’t find anything. Thanks

public int getNumberOfPages()
{
    XController xController = OODocument.getCurrentDocument().getXFrame().getController();

    XTextViewCursorSupplier supTextViewCursor =
                (XTextViewCursorSupplier) UnoRuntime.queryInterface(
                    XTextViewCursorSupplier.class, xController);

    XTextViewCursor curTextView = supTextViewCursor.getViewCursor();
    XPageCursor curPage =
                (XPageCursor) UnoRuntime.queryInterface(
                    XPageCursor.class, curTextView);
    curPage.jumpToLastPage();
    System.out.println("pages = " + curPage.getPage());
    return curPage.getPage();
}

I’m rethinking this now and wondering if its possible in javascript to find the string and then to return the page number that string is on. code I have is:

if(printOnPlainPaper == true)    {

            if(soApplet.isConnected())  
            {
                soDoc = soDoc + soApplet.getEncodedHtmlDocument( null );
                if(soDoc.indexOf("zzzzz"))  
                {                                       
                    alert("trueeeee");
                }
                else 
                {
                    soApplet.printDocument(PLAIN_PAPER, "1-");    // print page 1 to plain paper printer
                }
            }
        //soApplet.printDocument(PLAIN_PAPER, "1-");    // print page 1 to plain paper printer
    }

It can find the string but then how do I get it to tell me the page number its on?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:06:13+00:00Added an answer on June 13, 2026 at 1:06 am

    Incase anyone needs it I worked it out. Code below searches document , finds string and returns page number its on

    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();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below I have a jquery code which includes a textbox where the user can
I have the below code which goes through and returns disk information. When running
I have a textbox below which is created through this code: $('#txtWeight').each( function() {
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have below snippet of code in which TestClass is extending jPanel which is
I want to know is below code correct ? I have following code which
I have the code below which I use clone() and live() . The code
I have the code below which I use clone() and delegate() . The code
I have the below code, which iterates over a list based on a custom
I have the below code for my a Dialog box for a which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.