openoffice.macro 999 Bytes
Newer Older
Admin CED's avatar
Admin CED committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Sub ConvertToPDF( 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 


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