From: Ariel Constenla-Haile on
Hello Zak,

On Sunday 06 December 2009, 19:47, Zak McKracken wrote:
> Hi there,
>
> I'm not new to scripting, I know my Python (and some VBasic), but I've
> never done a Macro in OOo. Now I'd like to do the following:
>
> write a macro that will open an OOo file (I have drawings, texts and
> presentations), export it as a PDF (with a certain set of options) and
> close it again.
> By recording the pdf export, I coud find out the syntax for that, but
> recording only works if a document is open.
>
> Also, I'd need to tell OO to use the default name for the pdf, but in my
> recorded macro it's hard-coded. I'd need something in the form of
> "argv1(1) = [documentname]+'pdf'"
>
> Can anyone here help me?

don't know about the macro recorder, but you can use OOo API (in Python, Java,
C++, OOo Basic, ...) to fully automatize the PDF export, see
http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export

> Feel free to redirect me elsewhere if this is OT
> for this group.

you can join the OOo API mailing list: dev-subscribe(a)api.openoffice.org

Regards
--
Ariel Constenla-Haile
La Plata, Argentina

---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-unsubscribe(a)openoffice.org
For additional commands, e-mail: discuss-help(a)openoffice.org

From: "Zak McKracken" on
Am 07.12.2009, 10:25 Uhr, schrieb Mike Scott <mike(a)scottsonline.org.uk>:


> Almost what you want, but in OOo basic I'm afraid. The error checking is
> poor (truthfully, non-existent) because I use this from a web php
> script, not interactively.

No problem with OOo Basic. I used to know C64 Basic, worked with MS Office
VB, so the general stuff is not so hard to grasp.
That doesn't mean I'd understand all of this, but I'm not afraid of
running it :)


> To use from command line, you'll need something like
>
> /usr/local/bin/openoffice.org-2.3.0-swriter -headless
> "macro:///Standard.conversions.SaveAsPDF(\"$1\", \"$2\")"

I had to test a bit, but on Linux (SuSe 11.1, csh shell) with OOo3 it goes
like this:

openoffice.org3 -headless
"macro:///Standard.convert.SaveAsPDF(/absolute/path/to/file.odt)"

The quotes are necessary to deal with brackets. The shell would otherwise
insert spaces before and after them

-invisible instead of -headless works too, but produces an ugly error
statement after producing the pdf.

Other properties of the pdf can probably be influenced by using
"MakePropertyValue()" to set the properties described in
http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export
(thank you Ariel for pointing me to it!)
I'll try that later and post the results here (in case anyone else is
interested).


Big Cheers,

Zak



---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-unsubscribe(a)openoffice.org
For additional commands, e-mail: discuss-help(a)openoffice.org

From: "Zak McKracken" on
Arrright!

This goes to the OOo.general group (where the thing started) as well as to
the OOo.scripting one, where it is probably better placed.

I've done a python script that will call the OOBasic PDF export script and
convert all odp and odt files within one directory and its subdirectories
to pdf, then delete the original.


What did not work was the part where I tried to specify pdf conversion
options in the basic script (appended in the comments of the python
script).
Here's the part of the basic script that does the conversion:
<code>
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "writer_pdf_Export" ),))
</code>
I expected to be able to influence the options by doing something like
<code>
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "writer_pdf_Export" ), _
MakePropertyValue( "ReduceImageResolution", TRUE ),))
</code>
, but that seems to be wrong, the parameters are ignored.
In the example from
http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export#Filter_data_demo
only one single array of parameters is passed to the pdf export filter,
but either there is something wrong with the example or I didn't quite get
it.
The workaround is to start OOo export anything using the options you'd
like to have and then run the script, it will use those.


Anyways, you can spread the script, use it, enhance it, whatever. Would be
nice if you posted the results here or link to them.


Limitations of the script: kommas in filenames are not treated correctly
by ConvertToURL() (I had to rename some files), spaces seem to be no
problem. The only way the script makes a distiction between directories
and files is by searching for a "." in the name. This worked for me
because my files were all generated on windows by a windows user. Some
more thinking and/or python knowledge is required to make it work in the
general case.


Have fun,

Zak


P.S.: The script worked for me on SuSe 11.1, using Python 2.6 and OOo 3.1.
From: Ariel Constenla-Haile on
Hello Zak,

On Sunday 27 December 2009, 21:30, Zak McKracken wrote:
> This goes to the OOo.general group (where the thing started) as well as to
> the OOo.scripting one, where it is probably better placed.

no, for OOo API questions the best place is the API mailing list
dev(a)api.openoffice.org

> What did not work was the part where I tried to specify pdf conversion
> options in the basic script (appended in the comments of the python
> script).
> Here's the part of the basic script that does the conversion:
> <code>
> oDoc.storeToURL( cURL, Array(_
> MakePropertyValue( "FilterName", "writer_pdf_Export" ),))
> </code>
> I expected to be able to influence the options by doing something like
> <code>
> oDoc.storeToURL( cURL, Array(_
> MakePropertyValue( "FilterName", "writer_pdf_Export" ), _
> MakePropertyValue( "ReduceImageResolution", TRUE ),))
> </code>
> , but that seems to be wrong, the parameters are ignored.
> In the example from
> http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export#Filter_da
> ta_demo only one single array of parameters is passed to the pdf export
> filter, but either there is something wrong with the example or I didn't
> quite get it.

nothing's wrong with the example, so you didn't quite get it.
Re-read the Java code.

I quote myself (I was the one who wrote the tutorial):

XStorable.storeToURL() expects an URL as first parameter, and an array of
com.sun.star.beans.PropertyValue structs as second parameter, which implements
the com.sun.star.document.MediaDescriptor service, consisting of property
definitions. The media descriptor is used for loading/importing and
saving/exporting documents, please refer to the Developer's Guide for a
detailed explanation. In this case, it includes only the struct for the
FilterName, indicating the name of the filter for exporting Writer documents to
PDF.
You can fully customize the PDF export process by adding another PropertyValue
struct to the MediaDescriptor array: FilterData. This parameter is used to
pass properties specific for a special filter type. In the case of the PDF
export filter, another array of PropertyValue structs is expected.

Try the Python code attached (needs to start OOo in listening mode,
instructions at the top of the file).

Regards
--
Ariel Constenla-Haile
La Plata, Argentina
From: "Zak McKracken" on
Am 28.12.2009, 03:07 Uhr, schrieb Ariel Constenla-Haile
<ariel.constenla.haile(a)googlemail.com>:

Hi,

> no, for OOo API questions the best place is the API mailing list
> dev(a)api.openoffice.org

Ok ... can we move this thread there somehow?
I was reluctant to post on a developer list, because everything I'll ever
be developing is one script or two.

>> What did not work was the part where I tried to specify pdf conversion
>> options in the basic script (appended in the comments of the python
>> script).
>> Here's the part of the basic script that does the conversion:
>> <code>
>> oDoc.storeToURL( cURL, Array(_
>> MakePropertyValue( "FilterName", "writer_pdf_Export" ),))
>> </code>
>> I expected to be able to influence the options by doing something like
>> <code>
>> oDoc.storeToURL( cURL, Array(_
>> MakePropertyValue( "FilterName", "writer_pdf_Export" ), _
>> MakePropertyValue( "ReduceImageResolution", TRUE ),))
>> </code>
>> , but that seems to be wrong, the parameters are ignored.
>> In the example from
>> http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export#Filter_da
>> ta_demo only one single array of parameters is passed to the pdf export
>> filter, but either there is something wrong with the example or I
>> didn't
>> quite get it.
>
> nothing's wrong with the example, so you didn't quite get it.
I accept that. wasn't really sure about what I'm doing here, so advice is
appreciated.

> Re-read the Java code.
Hmm... Java is one of the languages I don't really know, but after
re-reading it the (n+1)th time, I think I understand the error I made.
what the export function expects is this:
filename,
array(PV("FilterName",filtername),PV("aFilterData",array(PV(option1,value),PV(option2,value)...)
)
while I tried to do this:
filename,
array(PV("FilterName",filtername),PV("FilterData",array(PV(option1,value),PV(option2,value)...
)))
the above probably isn't formally correct (sorry, I never learned this
stuff properly), but I hope it's understandable.

> Try the Python code attached (needs to start OOo in listening mode,
> instructions at the top of the file).

Thank you, Ariel.
It surely would have been more elegant not to mix python and OObasic (and
system calls), but learning a new API which follows principles unkown to
me is quite painful (did I mention I'm just a casual programmer?).
Do I understand the code right? You can either call
xPDFConfig.setPropertyValues() and later xPDFConfig.commitChanges() or
specify the export options in the actual exporter call after putting them
in aMediaDescriptor. If I use xPDFConfig, I won't have to set those
options everytime I call the pdf export.
Unluckily, I don't have time now to play with the python script, but I'll
keep it in a safe place for when I need it next.


From a user's point of view: As a not-experienced-yet-enthusiastic python
user I feel that the way of specifying the export options is a bit
roundabout. There is quite probably a good reason for that (which I may or
may not be able to understand), but I'd like to see something that just
goes "OO.currentDoc.export(filename, filtername, [properties : values])".
That would remove the need for arrays within arrays of things I need to go
and call a separate routine for.
Meaning: The UNO API sure is powerful, but it just as sure is confusing to
the uninitiated.

Cheers,

Zak


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-unsubscribe(a)openoffice.org
For additional commands, e-mail: discuss-help(a)openoffice.org