I’m using --headless mode to convert a docx file to a pdf file. The document contains a table of contents and a couple of indexes that need to be updated prior to conversion, because some data has been inserted into it by my process. I’ve created a macro for this and assigned it to “Storing or exporting copy of document” in “LibreOffice.” This allows the macro to be saved and run (since it can’t be saved with the docx).
It works when I open the document in the GUI and manually save it to a PDF. But when I use --headless mode, Writer hangs. Switching to --invisible mode showed me that an error is being thrown when the macro is executed: “Property or method not found: CurrentController.” The code is as follows. The error occurs on line 4.
Sub UpdateIndexes
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, "uno:UpdateAllIndexes", "", 0, Array())
End Sub
Is there a way to get this to run correctly in headless/invisible mode? Thank you.
Update: I removed --invisible from the call line and found that the error still occurs. So it’s not --headless or --invisible mode, but rather simply the fact that LO is being called from the command line, probably to export the file. I’m guessing the file isn’t opened the same way in that case as when it’s being edited.