Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java getPageNumber开放办公室_Java_Openoffice.org_Openoffice Writer - Fatal编程技术网

Java getPageNumber开放办公室

Java getPageNumber开放办公室,java,openoffice.org,openoffice-writer,Java,Openoffice.org,Openoffice Writer,我有下面的代码返回我的文档中的总页数。我可以用javascript soapplet.getNumberOfPages()调用它 我想做一个类似的方法,只返回页码。我找到了这个类com.sun.star.text.TextField.PageNumber,但我不知道如何返回一个PageNumber字符串。在javascript中,我将能够搜索文档中的某个字符串,并且根据找到该字符串的位置,我将能够确定该文档中存在该字符串的页码。然后我可以告诉打印机从有标题的纸盘打印这一页。我在谷歌上搜索了一两天

我有下面的代码返回我的文档中的总页数。我可以用javascript soapplet.getNumberOfPages()调用它

我想做一个类似的方法,只返回页码。我找到了这个类com.sun.star.text.TextField.PageNumber,但我不知道如何返回一个PageNumber字符串。在javascript中,我将能够搜索文档中的某个字符串,并且根据找到该字符串的位置,我将能够确定该文档中存在该字符串的页码。然后我可以告诉打印机从有标题的纸盘打印这一页。我在谷歌上搜索了一两天,什么也找不到。谢谢

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();
}
我现在正在重新思考这个问题,并想知道是否可以在javascript中找到字符串,然后返回该字符串所在的页码。我的密码是:

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
    }
它可以找到字符串,但是如何让它告诉我它的页码呢


谢谢

万一有人需要,我会解决的。下面的代码搜索文档,查找字符串并返回其上的页码

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();
}