In this document I have specified a Table of Content, I want to update this Table of Content and then save the file in any format I please.
For this I use the following script:
Code: Select all
' Save document as the given type.
Sub SaveAs( cType, cExtension, cFile )
On Error Goto test
cURL = ConvertToURL( cFile )
' Open the document. Just blindly assume that the document
' is of a type that OOo will correctly recognize and open
' without specifying an import filter.
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
Array(MakePropertyValue( "Hidden", True ),))
' in case OOo doesn't recognize the type then do nothing at all.
If Not IsNull(oDoc) Then
oIndexes = oDoc.getDocumentIndexes()
for i = 0 to oIndexes.getCount () - 1
oIndexes (i).update
next i
cFile = Left( cFile, Len( cFile ) - 4 ) + cExtension
cURL = ConvertToURL( cFile )
' Save the document using a filter.
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", cType ),)
oDoc.close( True )
EndIf
Exit Sub
test:
' We do not want any errors displayed.
On Error Goto End
If Not IsNull(oDoc) and Not IsEmpty(oDoc) Then
oDoc.close( True )
EndIf
End Sub
Topic 1 .................. 2
Topic 2 .................. 3
Topic 3 .................. 4
The headers Topic 1, Topic 2, and Topic 3 are respectively on pages: 2,3,7
When I open the file and manually update the ToC it displays the page numbers correctly,
but when I use my automated script it doesn't.
I think the problem here is that I load the document and while it's not entirely loaded I update the ToC.
Is there a way to check if the document is fully loaded and at that time update the ToC?