Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ooRexx & OpenOffice] How to convert odg to pdf/png by script ?

189 views
Skip to first unread message

Jean-Louis Faucher

unread,
Dec 11, 2009, 12:02:47 PM12/11/09
to
For my current work on ooRexx documentation, I need to convert 87 .odg
files to .pdf and .png
I do that by hand, and it's tedious.I tried to write an ooRexx script
which automates that, but I'm not familiar with OpenOffice automation.
What I want to do : load an .odg file, execute "export to pdf" and
"export to png" (with the default settings), close.
Maybe you can help me ?

Jean-Louis

My current script (does nothing except loading/closing the .odg
file) :

---------------

oDesktop = UNO.createDesktop()
xComponentLoader = oDesktop~XDesktop~XComponentLoader
url = makeUrl("AfterReply.odg") -- get the document from the current
folder

props = bsf.createArray(.UNO~PropertyValue, 1) -- create Java array
props[1]=uno.createProperty("ReadOnly", box("boolean",.true))

xDrawComponent = xComponentLoader~loadComponentFromURL(url, "_blank",
0, props)

/* created by macro register (OpenOffice Basic)
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "URL"
args2(0).Value = "file:///C:/tmp/f.pdf"
args2(1).Name = "FilterName"
args2(1).Value = "writer_pdf_Export"
args2(2).Name = "FilterData"
args2(2).Value = Array(Array("UseLosslessCompression",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Quality",
0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ReduceImageResolution",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("MaxImageResolution",
0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("UseTaggedPDF",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("SelectPdfVersion",
0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportNotes",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ExportBookmarks",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("OpenBookmarkLevels",
0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("UseTransitionEffects",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("IsSkipEmptyPages",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("IsAddStream",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ExportFormFields",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("HideViewerToolbar",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("HideViewerMenubar",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("HideViewerWindowControls",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ResizeWindowToInitialPage",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("CenterWindow",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("OpenInFullScreenMode",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("DisplayPDFDocumentTitle",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("Magnification",
0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Zoom",
0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("FirstPageOnLeft",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("EnableCopyingOfContent",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("EnableTextAccessForAccessibilityTools",
0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ExportLinksRelativeFsys",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("PDFViewSelection",
0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ConvertOOoTargetToPDFTarget",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("ExportBookmarksToPDFDestination",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("_OkButtonString",
0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("EncryptFile",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("DocumentOpenPassword",
0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("RestrictPermissions",
0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array
("PermissionPassword",
0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("",
0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))
dispatcher.executeDispatch(document, ".uno:ExportToPDF", "", 0, args2
())
*/

/* extracted from example10_swriter_pdf.rxo
props = bsf.createArray(.UNO~propertyValue, 2) -- create Java
array
props[1]=uno.createProperty("FilterName", "writer_pdf_Export")
props[2]=uno.createProperty("CompressMode", 2)

storeURL = substr(url, 1, lastpos(".", url)) || "pdf" -- create
output file name
xStorable~storeToUrl(storeURL, props) -- store the file with
props to URL
*/

xDrawComponent~dispose

::requires UNO.CLS -- get UNO support

-- A function for getting the file in the current folder
::routine makeUrl -- operating system independent
return ConvertToURL(stream(arg(1), "c", "query exists"))

rony

unread,
Dec 11, 2009, 5:58:18 PM12/11/09
to
Hi Jean-Louis,

Jean-Louis Faucher wrote:
> For my current work on ooRexx documentation, I need to convert 87 .odg
> files to .pdf and .png
> I do that by hand, and it's tedious.I tried to write an ooRexx script
> which automates that, but I'm not familiar with OpenOffice automation.
> What I want to do : load an .odg file, execute "export to pdf" and
> "export to png" (with the default settings), close.
> Maybe you can help me ?

Unfortunately, I do not have time to help you solve it with a script right now (family business
until Tuesday), but maybe the following pointers help you to solve the problem yourself:

- "bsf4oorexx/samples/OOo/ahammer/example23_sdraw_jpg.rxo": this short ooRexx script demonstrates
how to save draw pages as JPGs, you could choose other export formats as well;

- <http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export>: this excellent Wiki explains
all about using the OOo PDF export filter supplying Java examples which are *much easier* to
transcribe to ooRexx than the Basic examples; it makes an interesting reading anyway, as it explains
a lot of the available PDF features that many people do not know about,

- to create the correct file URL for OOo you should use the public routine
"uno.convertToUrl(filename)", cf. "refcardOOo.pdf",

- if you need to box the primitive Java values for the OOo property values, you could use the public
box() routine, cf. "refcardBSF4ooRexx.pdf" (BSF.CLS is required by UNO.CLS, hence all of its
functionality is available as well).

If you have questions, please ask, I will probably be able to check my newsgroups in between.

HTH,

---rony

P.S.: The above samples and the refcard are from the BSF4ooRexx package from
<http://wi.wu-wien.ac.at:8002/rgf/rexx/bsf4oorexx/current/>.

P.P.S.: In case you have a need to research the OOo UNO API interfaces, then you might want to check
out the dynamite utility in "bsf4oorexx/samples/OOo/UNO_API_info/frontend_UNO_API_info.rxo". The
accompanying HTML-file explains how to use that ooRexx script from the other OOo languages (Java,
Basic).

Jean-Louis Faucher

unread,
Dec 12, 2009, 11:41:58 AM12/12/09
to
Thanks Rony,

With yours pointers, I succeeded in writing my script.
I will commit it in incubator/DocMusings.

Maybe there is a little work remaining to do on the png export : For
rexxref/AfterReply.odg, the script generates a 12Kb png, whereas the
manual export (with default compression 6) generates a 15Kb png. I
don't see any difference between both, but maybe it's better to use
the same parameters as for manual export.
Nothing urgent, I don't plan to commit png files for the moment.

Jean-Louis

rony

unread,
Dec 12, 2009, 6:32:38 PM12/12/09
to
Jean-Louis:

Jean-Louis Faucher wrote:
> Thanks Rony,
>
> With yours pointers, I succeeded in writing my script.

Great!

> Maybe there is a little work remaining to do on the png export : For
> rexxref/AfterReply.odg, the script generates a 12Kb png, whereas the
> manual export (with default compression 6) generates a 15Kb png. I
> don't see any difference between both, but maybe it's better to use
> the same parameters as for manual export.
> Nothing urgent, I don't plan to commit png files for the moment.

It seems that one filter property may be named "FilterData" and the value being another array of
PropertyValues, where one PropertyValue may be named "Compression" with an int value in an unknown
range (maybe between 0 and 9 ?).

Here a few links that may help you (although in Basic they still show the "FilterData" PropertyValues):

- <http://www.openoffice.org/servlets/ReadMsg?list=dev&msgNo=6843>
- <http://www.oooforum.org/forum/viewtopic.phtml?p=226754>
- <http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=11769>: this one has a Basic
script in a scrollable window that uses an interesting number of "FilterData" PropertyValue names
and hints at those that are generally available

If that helps, it might be a good idea to post the Rexx script here as well, such that interested
readers can see how one may use Rexx to drive OpenOffice.org to do useful and helpful things for
Rexx programmers.

HTH,

---rony

Jean-Louis Faucher

unread,
Dec 13, 2009, 12:10:19 PM12/13/09
to
Thanks again, Rony

Now I generate png files that have the same size as by manual export
(compression 6, interlaced).
For the interested readers, the script is here :
http://oorexx.svn.sourceforge.net/viewvc/oorexx/incubator/DocMusings/openoffice/odg2image.rxo?view=log

Jean-Louis

rony

unread,
Dec 13, 2009, 4:06:31 PM12/13/09
to
Hi Jean-Louis,

Jean-Louis Faucher wrote:
> Thanks again, Rony
Glad, I could help a little bit.

That's a great, useful script to take advantage of OpenOffice.org's features!
Thank you very much for sharing it!

---rony

0 new messages