Hello Sander,
Hello,
I am using OOo in headless mode together with PyODConverter
(http://www.artofsolving.com/node/26). I made a little change to the
script so it will update the Table of Contents before outputting the
resulting document:
document = self.desktop.loadComponentFromURL(inputUrl, "_blank", 0,
_unoProps(Hidden=True, ReadOnly=True)
try:
indexes = document.getDocumentIndexes()
for i in range(0, indexes.getCount()):
index = indexes.getByIndex(i)
index.update()
except:
pass
document.storeToURL(outputUrl, _unoProps(FilterName=filterName))
However, the indexes aren't updated correctly. I.e. some entries in the
ToC point to the wrong page number.
It seems OOo needs some time to figure out how many pages are in the
document and what title is on what page. I see the same when I open my
document in OOo. When I open my document, it starts out saying that
there are 10 pages, a second later it's 11 and another second later 12.
It seems to be "reflowing" the document several times before everything
is layed out correctly (to borrow that term from web browsers).
If I delete the layout-cache file from the ODF container (and it's entry
in manifest.xml) then it starts out at a pagecount of 18 and reduces
back to 12.
if I add a 10 second sleep between opening the document and updating the
ToC, it does work correctly. But I don't want to add an arbitrary pause
in the document conversion.
Is there a way to force a reflow through the Python Uno API? Or is there
a way to get notified when OOo has finished reflowing and laying out the
document, so I can wait for it?
Sorry - but the answer is "no". The asynchronous layout of our
applications is an optimization to perform loading documents.
In an UI use case you will see the document asap ... and layout will
come later. But you are right ... loadComponentFromURL () is a
synchronous API (btw: the office itself uses the corresponding
dispatch() for loading documents) .. and so the document should be ready
after this method returns - but it isnt.
I will try to find a solution. Please file an issue on OOo and send it
to me ("[EMAIL PROTECTED]"). There exists two ideas:
a) loadComponentFromURL () make sure that layouting was done (my favorit)
b) a special event (send by the GlobalEventBroadcaster) will notify
finishing the asynchronous layout operation.
Kind regards,
Best Regards
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]