1
0
Fork 0
libreoffice/odk/examples/python/DocumentHandling
Daniel Baumann 8e63e14cf6
Adding upstream version 4:25.2.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-22 16:20:04 +02:00
..
tests Adding upstream version 4:25.2.3. 2025-06-22 16:20:04 +02:00
DocumentConverter.py Adding upstream version 4:25.2.3. 2025-06-22 16:20:04 +02:00
DocumentLoader.py Adding upstream version 4:25.2.3. 2025-06-22 16:20:04 +02:00
DocumentPrinter.py Adding upstream version 4:25.2.3. 2025-06-22 16:20:04 +02:00
DocumentSaver.py Adding upstream version 4:25.2.3. 2025-06-22 16:20:04 +02:00
README.md Adding upstream version 4:25.2.3. 2025-06-22 16:20:04 +02:00

Document Handling Examples

These examples are somehow similar to DocumentLoader in C++ and Java. To get started, first start LibreOffice listening on port 2083

$OFFICE_PROGRAM_PATH/soffice "--accept=socket,port=2083;urp;"

Each example script accepts -h to show the usage, e.g.

$OFFICE_PROGRAM_PATH/python DocumentLoader.py -h

You should use setsdkenv_unix for Unix/Linux and setsdkenv_windows.bat for Windows. In this way, the LibreOffice internal Python interpreter will be used.

Document Converter

$OFFICE_PROGRAM_PATH/python DocumentConverter.py ./tests/ "MS Word 97" doc /tmp/

This command searches LibreOffice documents recursively under directory ./tests and convert every found document to format Microsoft Word 97. The converted document can be found under directory /tmp.

Document Loader

$OFFICE_PROGRAM_PATH/python DocumentLoader.py ./tests/hello.odt

This command opens document ./tests/hello.odt in a separate window.

This script also accepts option to open an empty document. For example, to open an empty spreadsheet document:

$OFFICE_PROGRAM_PATH/python DocumentLoader.py --calc

Document Printer

$OFFICE_PROGRAM_PATH/python DocumentPrinter.py myprinter ./tests/hello.odt "1-3"

This command prints the first three pages of document ./tests/hello.odt on printer myprinter . You can also specify the page range in various format, e.g. 1,3-5.

Document Saver

$OFFICE_PROGRAM_PATH/python DocumentSaver.py path/to/hello.doc path/to/hello.odt

This command saves a Word document hello.doc as an OpenDocument file hello.odt.