Conversion de documents Word vers HTML/PDF avec OpenOffice.org

Ouvrir OpenOffice.org et faire :
Outils :: Macros :: Gérer les Macros :: OpenOffice.org Basic
puis
mes macros :: Standard :: Module1.

éditer et ajouter le code suivant :

Sub ConvertWordToPDF(cFile)
Dim oDoc As Object
Dim cURL As string
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.
On Error Resume Next
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array(MakePropertyValue("Hidden", True)))
If IsNull(oDoc) Then
MsgBox("Le document non trouvé ! URL invalide (doit commencer par file:///) ?", 16)
End If
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

Sub ConvertWordToHTML(cFile)
Dim oDoc As Object
Dim cURL As string
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.
On Error Resume Next
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array(MakePropertyValue("Hidden", True)))
If IsNull(oDoc) Then
MsgBox("Le document non trouvé ! URL invalide (doit commencer par file:///) ?", 16)
End If
cFile = Left(cFile, Len(cFile) - 4) + ".html"
cURL = ConvertToURL(cFile)

' Save the document using a filter.
oDoc.storeToURL(cURL, Array(MakePropertyValue("FilterName", "swriter: HTML (StarWriter)")))

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

Sauvegarder.

En ligne de commande, saisir :

/usr/bin/oowriter -invisible "macro:///Standard.Module1.ConvertWordToPDF(\"file:///<chemin>/<fichier.doc>\")"

pour obtenir dans le répertoire courant le fichier "fichier.doc" converti en PDF sous le nom "fichier.pdf".

/usr/bin/oowriter -invisible "macro:///Standard.Module1.ConvertWordToHTML(\"file:///<chemin>/<fichier.doc>\")"

pour obtenir dans le répertoire courant le fichier "fichier.doc" converti en HTML sous le nom "fichier.html".

On pourra utiliser tidy avec bonheur pour nettoyer le code HTML produit...