Updating contents index doesn't update page numbers

The Application Programming Interface and the OASIS Open Document Format

Updating contents index doesn't update page numbers

Postby Tim Grantham » Mon Jul 09, 2012 2:17 am

The Developer's Guide says to use the com.sun.star.text.XDocumentIndex update() method to update a contents index.

This method will certainly update the contents index for such things as a change in the number of levels that appear in the content index.

But it doesn't update the page numbers, even though manually updating a contents index in a text document DOES update the page numbers.

For example, I have a text document that has 300 pages. When I update the contents index in this document using the SDK, the hyperlinks in the content index work correctly but their page numbers are wrong. To correct the page numbers, I have to manually open the document, place the cursor in the contents index, and choose Tools > Update > Current Index.

I know the update() method is at least partly functioning, because my code changes the number of levels from the default of 10 to 4 before invoking the update() method, and this works as expected. But the page numbers are still wrong.

Here's the code I'm using:
Code: Select all   Expand viewCollapse view
    /**    Update all indexes in document
     * @param xDoc
     * @throws java.lang.Exception
    protected static void updateDocumentIndexes(XComponent xDoc)
            throws java.lang.Exception {

        // Get the DocumentIndexesSupplier interface of the document
        XDocumentIndexesSupplier xDocumentIndexesSupplier = (XDocumentIndexesSupplier) UnoRuntime.queryInterface(XDocumentIndexesSupplier.class, xDoc);

        // Get an XIndexAccess of DocumentIndexes
        XIndexAccess xDocumentIndexes = (XIndexAccess) UnoRuntime.queryInterface(
                XIndexAccess.class, xDocumentIndexesSupplier.getDocumentIndexes());

        int indexcount = xDocumentIndexes.getCount();

        for (int i = 0; i < indexcount; i++) {

            // Update each index
            XDocumentIndex xDocIndex = (XDocumentIndex) UnoRuntime.queryInterface(
                    XDocumentIndex.class, xDocumentIndexes.getByIndex(i));

            // Get the service interface of the ContentIndex
            String indexType = xDocIndex.getServiceName();

            if (indexType.contains("com.sun.star.text.ContentIndex")) {

                XPropertySet xIndex = (XPropertySet) UnoRuntime.queryInterface(
                    XPropertySet.class, xDocIndex);

                // Set TOC levels
                xIndex.setPropertyValue ( "Level", new Short ( (short) 4 ) );


Should I be reporting this as a bug, or am I misunderstanding how to update the page numbers in the contents field using the SDK?

I've had this problem with the 3.2, 3.3, and 3.4 SDKs.

Any help appreciated,
OpenOffice 4.1
Windows 7 Professional
Tim Grantham
Posts: 26
Joined: Thu Jan 06, 2011 12:03 am

Re: Updating contents index doesn't update page numbers

Postby B Marcelly » Mon Jul 09, 2012 11:42 am

In Basic you would do:
Code: Select all   Expand viewCollapse view

This is a method from interface com.sun.star.text.XTextDocument.
Maybe it is necessary to wait some time before updating index.

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Updating contents index doesn't update page numbers

Postby kingmax129 » Mon Sep 19, 2016 2:31 pm

Hi. I have same problem. Could you please update some information in this bugs?
OpenOffice 4.1.2 on Windows 10
Posts: 1
Joined: Mon Sep 19, 2016 11:56 am

Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 3 guests