AppyPrinciplesGetting started

Meta-command convert, corresponding to script appy/pod/converter.py, allows to call LibreOffice in server mode to ask him to convert a input file to some supported output format.

As a prerequisite to launching this command, LibreOffice must run in server mode, as explained in this page (read section named Managing LibreOffice).

The following example asks LibreOffice to convert a DOCX file into PDF.

appy convert /home/convertor/Planning.docx pdf

That being said, in the majority of cases, the input file to convert is generally an ODT or ODS file.

On completion, file /home/convertor/Planning.pdf should exist.

Unfortunately, for Windows users, meta-command appy is not available yet. You have 2 options: the first and wiser option is start using Linux 😁. The second is to determine paths to your Python interpreter and to appy/pod/converter.py, to produce a command that will look like this one.

C:\Program Files\Python312\python.exe C:\Users\Linus\Python\Python312\site-packages\appy\pod\converter.py C:\Users\Linus\fichier.docx pdf

Reference

All program options are documented hereafter.

Usage: appy convert fileToConvert output [options]
 or  : python3 converter.py fileToConvert output [options]
 
   "fileToConvert" is the absolute or relative pathname of the file you
   want to convert (or whose content like indexes need to be refreshed)
   
   "output" can be the output format, that must be one of:
            odt, ods, odp, htm, html, rtf, txt, csv, pdf, swf, doc, xls, ppt, docx, xlsx
            or can be the absolute path to the result file, whose extension must
            correspond to a valid output format.
 
   The Python interpreter running this command must be UNO-enabled (ie, the one
   being included in the LibreOffice distribution).
 
   LibreOffice must be running in server mode prior to running this command.
 
Options:
  -h, --help            show this help message and exit
  -e SERVER, --server=SERVER
                        The server IP or hostname that runs LibreOffice
                        (defaults to "localhost").
  -p PORT, --port=PORT  The port on which LibreOffice runs (default is 2002).
  -t TEMPLATE, --template=TEMPLATE
                        The path to a LibreOffice template from which you may
                        import styles.
  -o OPTIMAL_COL_WIDTHS, --optimalColumnWidths=OPTIMAL_COL_WIDTHS
                        Set this option to "True" if you want LibreOffice to
                        optimize column widths for all tables included in the
                        document. Alternately, specify a regular expression:
                        only tables whose name match will be processed. And if
                        the expression starts with char "~", only tables not
                        matching it will be processed. WARNING - If, for some
                        table, columns are both required to be optimized
                        (parameter "optimalColumnWidths") and distributed
                        (parameter "distributeColumns", only optimization will
                        take place.
  -d DISTRIBUTE_COLUMNS, --distributeColumns=DISTRIBUTE_COLUMNS
                        Set this option to "True" if you want LibreOffice to
                        distribute columns evenly for all tables included in
                        the document. Alternately, specify a regular
                        expression: only tables whose name match will be
                        processed. And if the expression starts with char "~",
                        only tables not matching it will be processed. WARNING
                        - If, for some table, columns are both required to be
                        optimized (parameter "optimalColumnWidths") and
                        distributed (parameter "distributeColumns", only
                        optimization will take place.
  -r RESOLVE_FIELDS, --resolveFields=RESOLVE_FIELDS
                        Set this option to "True" if you want LibreOffice to
                        replace the content of fields by their values. It can
                        be useful, for instance, if the POD result must be
                        included in another document, but the total number of
                        pages must be kept as is. Set this option to
                        "PageCount" instead of "True" to update this field
                        only. Note that field "PageNumber" is never resolved,
                        whatever the value of the option, because its value is
                        different from one page to another.
  -s SCRIPT, --script=SCRIPT
                        You can specify here (the absolute path to) a Python
                        script containing functions that the converter will
                        call in order to customize the process of manipulating
                        the document via the LibreOffice UNO interface. The
                        following functions can be defined in your script and
                        must all accept a single parameter: the Converter
                        instance. ***updateTableOfContents***, if defined,
                        will be called for producing a custom table of
                        contents. At the time this function is called by the
                        converter, converter.toc will contain the table of
                        contents, already updated by LibreOffice.
                        ***finalize*** will be called at the end of the
                        process, just before saving the result.
  -v, --verbose         Writes more information on stdout.
  -f PDF_OPTIONS, --pdf=PDF_OPTIONS
                        If the output format is PDF, you can define here
                        conversion options, as a series of comma-separated
                        key=value pairs, as in
                        "ExportNotes=True,PageRange=1-20". Available options
                        are documented in https://wiki.openoffice.org/wiki/API
                        /Tutorials/PDF_export.
  -i CSV_OPTIONS, --csv=CSV_OPTIONS
                        If the ouput format is CSV, you can define here
                        conversion options, as a comma-separated list of
                        values. Default options are: 59,34,76,1.Values
                        correspond to ASCII codes. The first one represents
                        the field separator. The most frequent values are: 59
                        (the semi-colon ;), 44 (the comma ,) and 9 (a tab).
                        The second value represents the text delimiter. The
                        most frequent values are: 34 (double quotes), 39
                        (single quotes) or no value at all (as in 59,,76,1).
                        The third one is the file encoding. The most frequent
                        values are 76 (UTF-8) and 12 (ISO-8859-1). Complete
                        documentation about CSV options can be found at https:
                        //wiki.openoffice.org/wiki/Documentation/DevGuide/Spre
                        adsheets/Filter_Options#Filter_Options_for_the_CSV_Fil
                        ter.
  -c, --ppp             Enable the POD post-processor (PPP). The PPP is a
                        series of UNO commands that react to PPP instructions
                        encoded within object names and must be executed at
                        the end of the process, when all other tasks have been
                        performed on the document, just before converting it
                        to another format or saving it to disk or as a stream.
  -a STREAM, --stream=STREAM
                        By default (stream = "auto"), if you specify
                        "localhost" as server running LibreOffice, the
                        converter and LibreOffice will exchange the input and
                        result files via the disk. If you specify anything
                        else, the converter will consider that LibreOffice
                        runs on a distant server: input and result files will
                        be carried as streams via the network. If you want to
                        bypass this logic and force exchange as streams or
                        files on disk, set this option to "True" for stream or
                        "False" for disk. You may also specify "in" (the input
                        file is streamed and the result is written on disk) or
                        "out" (the input file is read on disk and the result
                        is streamed).
  -g PAGESTART, --pageStart=PAGESTART
                        Specify an integer number different from 1 and the
                        produced document's page numbering will start at this
                        number.
↥ Back