Run Event-based Macro Headless mode

Hi everyone!

I’ve written a small java code that use UNO API to load an odt and extract the text from it.

I need to run LibreOffice in headless mode and I also need to execute macros inside the loaded doc.

I’ve tried to load an odt with a macro on it, that activates on Document Load. If I run the code normally, the macro would be executed, but with headless flag not.

Is there a way to execute the event-based macro in headless mode?

Thanks!

if you execute from Java, you can execute the same code of the macro, from Java, of course you need some changes, but, it’s possible.

Add your path of document with macro, to security path in macros in Tools->Options

I test with:

soffice --headless "/home/mau/test.ods"

the macro in event Open Document execute correctly.

Thanks Mauricio!

After adding the doc path into security path, I can execute the macro from the command line. Unfortunately, It still doesn’t work in java code.
Maybe the problem is the --accept flag in the bootstrap process.
Here the code that I use to retrieve the context:

xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(new String[]{"--headless"});

If I remove --headless, office GUI starts and the macros is executed. How can I solve it?