Ask Your Question

How to automatically update indices in headless mode?

asked 2015-02-21 11:16:32 +0200

gvx gravatar image

I'm using --convert-to to convert a document generated by a script to PDF. This document contains a table of content, but this table is unpopulated. There is the menu-item "update all indexes" which does the thing I want it to do, but I can't do any user interaction. There might be a way to use the UpdateAllIndexes uno dispatch, but I wouldn't know how as the documentation for these things is either missing or very well hidden.

So: how do I update the table of content of a document without user interaction?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-02-22 11:59:24 +0200

pierre-yves samyn gravatar image

Hi - One solution might be to run a macro that would do the job (open the document, update the index, export to pdf format).

Command line: soffice.exe "macro:///Standard.Module1.PysIndexer(a.odt)"

Note: paths must be provided

Sample Code:

sub PysIndexer(sDocUrl as string)

dim oDocument as object
dim dispatcher as object

dim propExp(0) as new

dim sNewUrl as string

if fileExists(sDocUrl) then
    oDocument = starDesktop.loadComponentFromUrl(convertToUrl(sDocUrl), "_blank", 0, array())

    dispatcher = createUnoService("")
    dispatcher.executeDispatch(oDocument.CurrentController.Frame, ".uno:UpdateAllIndexes", "", 0, Array())

    propExp(0).Name = "FilterName"
    propExp(0).Value = "writer_pdf_Export"


    sNewUrl = GetFileNameWithoutExtension(sDocUrl) & ".pdf"

    oDocument.storeToURL(convertToUrl(sNewUrl), propExp())
end if

end sub
edit flag offensive delete link more


I needed to pass an absolute filename to the macro, but then it worked!

gvx gravatar imagegvx ( 2015-02-22 13:04:21 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-02-21 11:16:32 +0200

Seen: 1,125 times

Last updated: Feb 22 '15