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? Feel free to redirect me elsewhere if this is OT
for this group.
Cheers,
Zak
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-u...@openoffice.org
For additional commands, e-mail: discus...@openoffice.org
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-su...@api.openoffice.org
Regards
--
Ariel Constenla-Haile
La Plata, Argentina
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.
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\")"
Give or take a quote or three (all on one line, of course).
Just don't ask me what it all means - please!!! :-)
' from http://www.xml.com/pub/a/2006/01/11/from-microsoft-to-openoffice.html
' Save document as an Acrobat PDF file.
Sub SaveAsPDF( cFile )
cURL = ConvertToURL( cFile )
' Open the document. Just blindly assume that the document
' is of a type that OOo will correctly recognize and open
' without specifying an import filter.
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
Array(MakePropertyValue( "Hidden", True ),))
cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
cURL = ConvertToURL( cFile )
' Save the document using a filter.
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "writer_pdf_Export" ),)
oDoc.close( True )
End Sub
' Save document as a Microsoft Word file.
Sub SaveAsDoc( cFile )
' mostly a copy of SaveAsPDF
cURL = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, (_
Array(MakePropertyValue( "Hidden", True ),))
cFile = Left( cFile, Len( cFile ) - 4 ) + ".doc"
cURL = ConvertToURL( cFile )
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "MS WinWord 6.0" ),)
oDoc.close( True )
End Sub
' Save document as an OpenOffice 2 file.
Sub SaveAsOOO( cFile )
' mostly a copy of SaveAsPDF. Save as an OpenOffice file.
cURL = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
Array(MakePropertyValue( "Hidden", True ),))
' Set output file extension based on lower-case
' version of input extension.
Select Case LCase(Right(cFile,3))
Case "ppt" ' PowerPoint file.
cFileExt = "odp"
Case "doc" ' Word file.
cFileExt = "odt"
Case "xls" ' Excel file.
cFileExt = "ods"
Case Else
cFileExt = "xxx"
End Select
cFile = Left( cFile, Len( cFile ) - 3 ) + cFileExt
cURL = ConvertToURL( cFile )
oDoc.storeAsURL( cURL, Array() )
oDoc.close( True )
End Sub
Function MakePropertyValue( Optional cName As String, Optional uValue ) _
As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
--
Mike Scott Harlow Essex England.(mike -a-t- [deletethis]
scottsonline.org.uk)
(Processing of this email by 3rd parties in relation to advertising
services is forbidden.)
> 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