Updating contents index doesn't update page numbers
Posted: 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:
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.
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();
}
}
I've had this problem with the 3.2, 3.3, and 3.4 SDKs.
Any help appreciated,
Thanks,
Tim.