Apache OpenOffice (AOO) Bugzilla – Issue 68579
Table of Content Page Numbers wrong when updated from Macro via command line
Last modified: 2013-08-07 14:44:35 UTC
When using OpenOffice Basic to update the table of contents for large documents generated outside of the OpenOffice, the table of contents are not updated correctly with the correct page numbers unless you wait a minimum of 30 seconds to allow open office to repaginate and create the layout cache. If the document is opened, and then saved. The page numbers are generated correctly as the layout cache seems to have been updated correctly. If using the dispatcher and UNO to update the table of contents everything updates correctly, however, this can only be used if OO is going to be running in the foreground and not being used to batch conversion of files to PDF. The following is some sample macro code: Sub SaveAsPDF( cFile ) Dim oDoc as Object Dim oIndexes as Object Dim oIndex as Object cURL = ConvertToURL( cFile ) oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, (_ Array(MakePropertyValue( "Hidden", True ),)) cFile = Left( cFile, Len( cFile ) - 4 ) + ".doc" cURL = ConvertToURL( cFile ) ' Update the Indexes (does not work correctly on 100+ page documents) oIndexes = oDoc.getDocumentIndexes() for i = 0 to oIndexes.Count -1 oIndexes(i).update next i ' Save the document using a PDF filter. cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf" cURL = ConvertToURL( cFile ) oDoc.storeToURL( cURL, Array(_ MakePropertyValue( "FilterName", "writer_pdf_Export" ),) oDoc.close( True ) end sub Also attached is a sample document. If the document is opened normally and the uno macro is allowed to run it works correctly. But the UI is not going to be available when this is run from a batch mode via ANT during a build.
Created attachment 38483 [details] Sample Document
Reassigned to ES.
ES->CN: please, have a look.
cn->tl: I can reproduce this. Just download the attached document. Do not open it. Then copy the macro and modify and run it. Open the created pdf. The last entries of the content table have a correct link but a wrong page number.
TL->FME: Please take ove as discussed. Thanks!
Sub Main Dim oDoc as Object Dim oIndexes as Object Dim oIndex as Object Dim aHidden(1) as new com.sun.star.beans.PropertyValue aHidden(0).Name = "Hidden" aHidden(0).Value = true Dim aFilter(1) as new com.sun.star.beans.PropertyValue aFilter(0).Name = "FilterName" aFilter(0).Value = "writer_pdf_Export" cFile = "x:\tl\AcknowledgeServicePlan.odt" cURL = ConvertToURL( cFile ) oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, aHidden, ) cFile = Left( cFile, Len( cFile ) - 4 ) + ".doc" cURL = ConvertToURL( cFile ) ' Update the Indexes (does not work correctly on 100+ page documents) oIndexes = oDoc.getDocumentIndexes() for i = 0 to oIndexes.Count -1 oIndexes(i).update next i ' Save the document using a PDF filter. cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf" cURL = ConvertToURL( cFile ) oDoc.storeToURL( cURL, aFilter, ) oDoc.close( True ) End Sub
FME: Set target and prio.
.
Exactly my problem too. I have a master document, with 20 subdocuments, in total about 150 real pages. Update TOC with a basic macro works only partially. For about half of the chapters, page numbers upto 300 can be seen in the TOC. Adding several minutes of delays does not help. Tried adding a "event listener" too, and wait until it's quiete, but that did not help either. The UNO dispatcher trick does not work. So I'm stuck...