1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65pylokit
=======
A python CFFI wrapper for LibreOfficeKit. Tested in cpython2,
cpython3, and pypy. LibreOfficeKit currently works only on Linux systems.
Requirements
------------
An installation of LibreOffice >= 4.3.0 is required on the same machine.
If you are using cpython you need *libffi-dev* in order to compile CFFI.
Installation
------------
You are encouraged to install pylokit on a python *virtualenv*.
.. code:: bash
pip install pylokit
Examples
--------
A basic conversion from a rtf file to a doc:
.. code:: python
from pylokit import Office
import os
lo_path = "/path/to/libreoffice/program/dir"
with Office(lo_path) as lo:
with lo.documentLoad("myfile.rtf") as doc:
doc.saveAs("myfile.doc")
os._exit(0)
Same conversion passing an explicit format and filter options:
.. code:: python
from pylokit import Office
import os
lo_path = "/path/to/libreoffice/program/dir"
with Office(lo_path) as lo:
with lo.documentLoad("myfile.rtf") as doc:
doc.saveAs("myfile.doc", fmt="docx", options="skipImages")
os._exit(0)
The usage of a context manager is needed to properly handle LibreOfficeKit
file locking.
The use of _exit() instead of default exit() is required because in some
circumstances LibreOffice segfaults on process exit.
Acknowledgements
----------------
Project inspired by Olly Betts' `lloconv <https://gitlab.com/ojwb/lloconv>`_.