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? Feel free to redirect me elsewhere if this is OT for this group.


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.)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to