Skip to main content

oodocument

Connects vía Uno bridge interface with libreoffice to perform simple format conversions and replace string over a document. Pypi Package link

Dependencies

If you are virtualenv user, you need to create with option --system-site-packages as it needs to use system site-packages which has uno module installed by $ sudo apt-get install python3-uno. (Unfortunately, uno module is not available from pip).

 sudo apt-get install libreoffice-common python3-uno

You must run headless libreoffice service (libreoffice executable can be different on different gnu/linux distros, another options can be soffice or loffice)

/usr/bin/libreoffice --headless --nologo --nofirststartwizard --accept="socket,host=0.0.0.0,port=8001;urp"

Features

  • Search and replace
  • Support font colors, background and clear hyperlinks
  • Support file Conversion to pdf, txt, odt and docx

Install

pip install oodcument

Examples

Search and Replace

Will open input.docx file, search for holamundo String and replacing it by XXX, then would save the output to output.pdf with pdf format.

from oodocument import oodocument
data = {}
data['holamundo'] = 'XXX'
oo = oodocument('./input.docx', host='0.0.0.0', port=8001)
oo.replace_with(data, './output.pdf', 'pdf')
oo.dispose()

Search and Replace with Indexes

Will open input.docx file with holamundo String. The package will found indexes and replace mundo String and replacing it by XXX, then would save the output to output.pdf with pdf format.

In this case, you must build a 3-component tuple with the following format:(start_index,end_index,text_to_replace)

from oodocument import oodocument
data = []
data.append((5,10,'XXX'))
oo = oodocument('./input.docx', host='0.0.0.0', port=8001)
oo.replace_with_index(data, './output.pdf', 'pdf')
oo.dispose()

Another Feature is the possibility of adding an offset parameter in replace_with_index

from oodocument import oodocument
data = []
data.append((4,9,'XXX'))
oo = oodocument('./input.docx', host='0.0.0.0', port=8001)
oo.replace_with_index(data, './output.pdf', 'pdf',1)
oo.dispose()

Search and Replace with Indexes in Header

Will open input.docx file with holamundo String in header. You know the name of style contains header.In that case , the style name is "Default Style".

from oodocument import oodocument
data = []
header_style_name = "Default Style"
neighbor_character = 20
data.append((4, 10, "XXX", "mundo"))
oo = oodocument("./input.docx", host="0.0.0.0", port=8001)
oo.replace_with_index_in_header(data, "./output.pdf", "pdf", 0, neighbor_character, header_style_name)
oo.dispose()

Will open input.docx file, search for holamundo String and replacing it by XXX with yellow background and red color font, then would save the output to the same file.

from oodocument import oodocument
data = {}
data['holamundo'] = 'XXX'
oo = oodocument('./input.docx', host='0.0.0.0', port=8001)
oo.set_font_color(255, 255, 0)
oo.set_font_back_color(255, 0, 0)
oo.set_clear_hyperlinks(False) # default value is True
oo.replace_with(data)
oo.dispose()

Will convert input.docx file to output.txt file with txt format

from oodocument import oodocument
oo = oodocument('./input.docx', host='0.0.0.0', port=8001)
oo.convert_to('./output.txt', 'txt')
oo.dispose()

Metadata

Release files for oodocument 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oodocument 0.0.8
File Size Uploaded Provenance Actions
oodocument-0.0.8.tar.gz 5.2 kB Without provenance Details for oodocument-0.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oodocument 0.0.8
File Interpreter ABI Platform Actions
oodocument-0.0.8-py3-none-any.whl Python 3 none any Details for oodocument-0.0.8-py3-none-any.whl

Total release size: 23.1 kB

Release files / oodocument-0.0.8.tar.gz

Download URL oodocument-0.0.8.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
52215e1c986cc82819c8f00f60721621b3619192fa9a01c4a2134a216b7cd718
BLAKE2b-256 checksum
How to use checksums
2906cfbdd0ec682b35403590aa15c948cef879d4cc44787099bfee3420a81613
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.2

Release files / oodocument-0.0.8-py3-none-any.whl

Download URL oodocument-0.0.8-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f4d0231dd156fa17dc2a4b16d1d42832db31233e4de099e00ff3caa3550b64c
BLAKE2b-256 checksum
How to use checksums
690796ba05e0f0077ce838634b00c534e4570543cf5a5151f3ce1bbc9329e79f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.2

Security for oodocument 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page