Macro from command line: ThisComponent.CurrentController not found

Hello!

I have a macro which I want to be executed whenever a Writer document is
being converted to a PDF. So I wrote my macro and assigned it to the
appropriate event. And it works. At least, from within a running
GUI-Session.

If I try to do the conversion via command line, I get this error message:
<----- snip ----->
BASIC runtime error.
Property or method not found: CurrentController
<----- snap ----->

The command I use to invoke LibreOffice is:
<----- snip ----->
lowriter --convert-to pdf:writer_pdf_Export test.odt
<----- snap ----->

It is later planned to have it run in headless mode on a machine with no X
server, but I removed those options to get an error message.

I assume that in this mode, there is no "CurrentController" (because there
is no Writer window?) and hence, the error. But what can I do about it?
Create one myself? How?

System is Kubuntu 13.04 with LibreOffice 4.0.2.

Hello!

I have a macro which I want to be executed whenever a Writer document is
being converted to a PDF. So I wrote my macro and assigned it to the
appropriate event. And it works. At least, from within a running
GUI-Session.

If I try to do the conversion via command line, I get this error message:
<----- snip ----->
BASIC runtime error.
Property or method not found: CurrentController
<----- snap ----->

The command I use to invoke LibreOffice is:
<----- snip ----->
lowriter --convert-to pdf:writer_pdf_Export test.odt
<----- snap ----->

It is later planned to have it run in headless mode on a machine with no X
server, but I removed those options to get an error message.

I assume that in this mode, there is no "CurrentController" (because there
is no Writer window?) and hence, the error. But what can I do about it?

for printing to PDF i assume there must be a "opened" document (who can been hidden) as soon the document is open it becomes "ThisComponent" who has its "CurrentController"

Hope it helps

Fernand

A user who could not post directly to the list because he was using his phone
with a non-matching e-mail address asked me why I was using
CurrentController. I think I better write the answer to the list so everyone
can participate.

The macro is rather complex. The documents are invoices containing text
table with a list of items and their prices. They are created by a
third-party program. I supply a template and the program fills in the data
from its database.

Now, it can happen that the table with the items is longer than one page
(even longer than two or three) pages. The macro will detect this and split
the table at those places, adding a subtotal to the foot of each page and a
carry over on the start of the next page. I plan to add this macro to the
template so that it automatically executes when a PDF is generated.

Example: The document I get looks like this (I hope the layout survives ;)):

<----- snip ----->

<----- snap ----->

After the macro is done, the document looks like this:

<----- snip ----->

<----- snap ----->

As you can see, it's pretty complex and due to the lack of documentation,
the only way to achieve this result was to replicate the steps I would
otherwise do manually. That means getting a view cursor (which is a part of
the current controller). Then I use my view cursor to do the stuff. I put it
in the last column of the first row. Then I go down cell by cell, summing up
values on way. Until the page changes. Then I go back up, insert subtotal
and carry over and finally split the table between them.

If there is another way to do it without CurrentController, I have not found
it.

If it helps, I can post the macro but it's a bit lengthy...