REM  *****  BASIC  *****

Sub Main
  
End Sub

' Сохранить документ в формате OpenOffice.
Sub SaveAsOOO( cFile ) 
   cURL = ConvertToURL( cFile )
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
            Array(MakePropertyValue( "Hidden", True ),))

   ' Расширение нового файла выбирается на основании расширения
   ' исходного файла, переведённого в нижний регистр.
   Select Case LCase(Right(cFile,4))
     Case ".ppt"         ' PowerPoint file.
       cFileExt = ".odp"
     Case "pptx"         ' PowerPoint file.
       cFileExt = "odp"
     Case ".doc"         ' Word file.
       cFileExt = ".odt"
     Case "docx"         ' Word file.
       cFileExt = "odt"
     Case ".xls"         ' Excel file.
       cFileExt = ".ods"
     Case "xlsx"         ' Excel file.
       cFileExt = "ods"
     Case Else
       cFileExt = ".odf"
    End Select
       
   cFile = Left( cFile, Len( cFile ) - 4 ) + cFileExt
   cURL = ConvertToURL( cFile )
   
   oDoc.storeAsURL( cURL, Array() )
   oDoc.close( True )
   
End Sub

Sub ConvertWordToPDF(cFile)
    cURL = ConvertToURL(cFile)
   
    oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array(MakePropertyValue("Hidden", True), ))
    
    cFile = Left(cFile, Len(cFile) - 4) + ".pdf"
    cURL = ConvertToURL(cFile)
    
    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
