libreoffice output filter names

2.2k views Asked by At

Anyone knows how to obtain a list of the available output filter names (used with --headless --convert-to options ) in a libreoffice installation? After a deep search, I've just found a list here, but no how to read the availables one.

1

There are 1 answers

1
Jim K On

Here is the code that generated the list. I found it by clicking the "Thread Prev" link. I also cleaned it up slightly and changed style names for LibreOffice.

Sub PrintFilterNames
    oFF = createUnoService( "com.sun.star.document.FilterFactory" )
    oFilterNames = oFF.getElementNames()

    ' Now print the filter names.
    ' For i = LBound( oFilterNames ) To UBound( oFilterNames )
    ' Print oFilterNames(i)
    ' Next

    ' Create a Writer doc and save the filter names to it.
    oDoc = StarDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, Array() )
    oText = oDoc.getText()
    oCursor = oText.createTextCursor()
    oCursor.gotoEnd( False )

    oText.insertString( oCursor, "Filter Names", False )
    oCursor.ParaStyleName = "Heading 1"
    InsertParaBreak( oText, oCursor )
    oCursor.ParaStyleName = "Default Style"
    InsertParaBreak( oText, oCursor )

    ' Print the filter names into a Writer document.
    For i = LBound( oFilterNames ) To UBound( oFilterNames )
        oText.insertString( oCursor, oFilterNames(i), False )
        InsertLineBreak( oText, oCursor )
    Next
    InsertParaBreak( oText, oCursor )
    InsertParaBreak( oText, oCursor )
    oText.insertString( oCursor, "Filter Names and their Properties", False)
    oCursor.ParaStyleName = "Heading 1"
    InsertParaBreak( oText, oCursor )
    oCursor.ParaStyleName = "Default Style"

    ' Tab stops at:
    ' 0.25 inch (2.54 cm x 0.25)
    ' 0.50 inch (2.54 cm x 0.50)
    ' 2.00 inch (2.54 cm x 2.00)
    oCursor.ParaTabStops = Array(_
        MakeTabStop( 2540 * 0.25 ),_
        MakeTabStop( 2540 * 0.50 ),_
        MakeTabStop( 2540 * 2.00 ) )

    ' Print the filter names and their parameters.
    For i = LBound( oFilterNames ) To UBound( oFilterNames )
        InsertParaBreak( oText, oCursor )

        cFilterName = oFilterNames(i)
        aFilterProps = oFF.getByName( cFilterName )

        oText.insertString( oCursor, cFilterName, False )

        For j = LBound( aFilterProps ) To UBound( aFilterProps )
            oFilterProp = aFilterProps(j)

            InsertLineBreak( oText, oCursor )
            oText.insertString( oCursor, CHR(9)+oFilterProp.Name, False )

            nFilterPropValueVarType = VarType( oFilterProp.Value )
            If nFilterPropValueVarType = 8201 Then
            ' VarType 8201 means a sequence of PropertyValue's.
            oFilterPropNames = oFilterProp.Value
            For k = LBound( oFilterPropNames ) To UBound(oFilterPropNames )
                InsertLineBreak( oText, oCursor )
                oText.insertString( oCursor, CHR(9)+CHR(9)+_
                oFilterPropNames(k).Name+CHR(9)+CSTR(oFilterPropNames(k).Value), False )
            Next k
            ElseIf nFilterPropValueVarType = 8200 Then
                ' VarType 8200 means a sequence of Strings.
                oFilterPropNames = oFilterProp.Value
                For k = LBound( oFilterPropNames ) To UBound(oFilterPropNames )
                    InsertLineBreak( oText, oCursor )
                    oText.insertString( oCursor, CHR(9)+CHR(9)+ oFilterPropNames(k), False )
                Next k
                ElseIf nFilterPropValueVarType> 1 And nFilterPropValueVarType<= 12 Then
                    oText.insertString( oCursor, CHR(9)+CSTR(oFilterProp.Value), False )
                Else
                oText.insertString( oCursor, CHR(9)+"?? unknown type ?? - "+CSTR(nFilterPropValueVarType), False )

            EndIf
        Next j

        InsertParaBreak( oText, oCursor )
    Next i

    InsertParaBreak( oText, oCursor )
End Sub

Private Sub InsertLineBreak( oText, oCursor )
    oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.LINE_BREAK, False )
End Sub

Private Sub InsertParaBreak( oText, oCursor )
    oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
End Sub


' Create and return a tab stop.
' An array of what this function returns, is used
' to set the tab stops of a paragraph.
'
' Parameters....
' nPosition - position in tab stop, in 1000'th of cm.
' nAlign - optional, if specified, must be one of...
' com.sun.star.style.TabAlign.LEFT = 0

' com.sun.star.style.TabAlign.CENTER = 1
' com.sun.star.style.TabAlign.RIGHT = 2
' com.sun.star.style.TabAlign.DECIMAL = 3
' com.sun.star.style.TabAlign.DEFAULT = 4

' cDecimalChar - optional, if specified, only applies to a DECIMAL tab stop,
' and specified the character which is recognized as
' the decimal point separator.
' cFillChar - optional, if specified, specifies the char that fills the space
' between tab stops.
Private Function MakeTabStop( ByVal nPosition As Long,_
        Optional nAlign,_
        Optional cDecimalChar,_
        Optional cFillChar _
        ) As com.sun.star.style.TabStop
    If IsMissing( nAlign ) Then
        nAlign = com.sun.star.style.TabAlign.LEFT
    EndIf

    oTabStop = createUnoStruct( "com.sun.star.style.TabStop" )

    oTabStop.Position = nPosition
    oTabStop.Alignment = nAlign

    If Not IsMissing( cDecimalChar ) Then
        oTabStop.DecimalChar = cDecimalChar
    EndIf
    If Not IsMissing( cFillChar ) Then
        oTabStop.FillChar = cFillChar
    EndIf

    MakeTabStop() = oTabStop
End Function