Updating contents index doesn't update page numbers

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Tim Grantham
Posts: 32
Joined: Thu Jan 06, 2011 12:03 am

Updating contents index doesn't update page numbers

Post by Tim Grantham »

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

    /**    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 ) );
            }

            xDocIndex.update();
        }
    }
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,
Thanks,
Tim.
OpenOffice 4.1
Windows 7 Professional
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Updating contents index doesn't update page numbers

Post by B Marcelly »

Hi,
In Basic you would do:

Code: Select all

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

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
kingmax129
Posts: 1
Joined: Mon Sep 19, 2016 11:56 am

Re: Updating contents index doesn't update page numbers

Post by kingmax129 »

Hi. I have same problem. Could you please update some information in this bugs?
OpenOffice 4.1.2 on Windows 10
Post Reply