I have an issue with a OOBASIC macro I have installed in OOo 2.3.1 for Writer on WinXP:
Code: Select all
Sub SaveAsPDF( cFile )
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 ),))
' update all indexes
oIndexes = oDoc.getDocumentIndexes()
for i = 0 to oIndexes.getCount () - 1
oIndexes (i).update
next i
' save updated file
oDoc.storeAsURL( cURL, Array () )
' calculate the PDF file name
'cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
'cURL = ConvertToURL( cFile )
' Save the document using a filter.
'oDoc.storeToURL( cURL, Array(_
' MakePropertyValue( "FilterName", "writer_pdf_Export" ),)
oDoc.close( True )
End Sub
Function MakePropertyValue( Optional cName As String, Optional uValue ) _
As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
/cygdrive/c/Program\ Files/OpenOffice.org\ 2.3/program/soffice.exe -invisible 'macro:///Standard.Export2PDF.SaveAsPDF(u:\l1ifman.odt)'
However the script doesn't quite work out as expected. Researching the issue, it seems that because the doument is likey to be reflowed/repaginated after loading as an asynchronous process, this indexes get updated with inaccurate page numbers (many headings on the same page typically), and the export step generates a PDF which contains a lot of contiguous blank pages (with headers and footers though) where presumably a step change in the reflow moved the data to a new page while the export was being done.
All of this maybe exasperated by the fact I have around 90 OLE OO draw objects in my writer document (all in frames), and maybe even more so because my ~200 page doc has an extra ~100 pages added to it by a Perl script (auto code documentation) bumping it up to over 300 pages.
It seems to me that it is buggy behaviour that "update-index" and "export" like operations can create incorrect results. An asynchronus relow is useful functionality that makes editing much faster after a load, but operations that rely on the results of a reflow ought to wait until the reflow is complete shouldn't they? Possibly, they ought to be able to expidite the reflow so that the results can be obtained quicker, but that is a seperate issue.
I did see some java related workaround using some kind of refresh() call. I added an oDoc.refresh() to the macro above, but it had no effect on my problem. Probably the wrong function to call I guess. I can't find a workaround for a Basic Macro mechanism to pause until the document reflow is complete.
Anyway, Is this a bug I should file (Filed now, as 86024)? Is there a work around that works in OOBASIC? I'll be happy to put together a demo document (with non sensitive contents) to demonstrate the problem if it helps. Since this jeopardises the whole of my current project, I'll be more or less happy to do just about anything (Example doc now attached to issue 86024).
Thanks,
Ratbert