Skip to content

alinbsp/unoconvert

Repository files navigation

unoconvert

This is a modular reimplementation of the unoconv tool, which converts between office document formats using LibreOffice/OpenOffice.

Overview

The original unoconv.py script has been restructured into a modular package that allows for both command-line usage and programmatic integration. The refactored version maintains all the functionality of the original script while providing a cleaner, more organized codebase.

Structure

The package is structured as follows:

unoconvert/
├── __init__.py         # Package initialization and high-level API
├── cli.py              # Command-line interface
├── config.py           # Configuration handling
├── connection.py       # LibreOffice connection management
├── converter.py        # Document conversion logic
├── formats.py          # Format definitions and handling
└── listener.py         # Listener functionality

Features

  • Convert documents between various formats
  • Start LibreOffice/OpenOffice listeners for faster conversions
  • Customize document conversion with filters and templates
  • Use programmatically in Python applications
  • Same command-line interface as the original unoconv

Installation

pip install unoconvert

Usage

Command-line Usage

The command-line interface is similar to the original unoconv:

# Convert a document to PDF
unoconvert -f pdf document.odt

# Start a listener
unoconvert -l

# Show available formats
unoconvert --show

Programmatic Usage

The modular version can be easily used in Python code:

from unoconvert import convert

# Simple conversion
convert('document.odt', 'document.pdf')

# Conversion with options
convert(
    'spreadsheet.xlsx',
    'spreadsheet.pdf',
    format='pdf',
    doctype='spreadsheet',
    template='template.ott',
    verbose=1
)

# Start a listener
from unoconvert import listen
listen()

# Get available formats
from unoconvert import get_formats
formats = get_formats(doctype='document')

Requirements

  • Python 3.6+
  • LibreOffice or OpenOffice

Differences from Original

This modular version maintains all the functionality of the original unoconv script, but with several improvements:

  1. Modular Structure: Code is organized into logical modules for better maintainability
  2. Clean API: Simple, intuitive API for programmatic usage
  3. Modern Python: Uses modern Python features and best practices
  4. Better Error Handling: More consistent and informative error messages
  5. Easier Integration: Can be used as a library in other Python projects

Example

See example.py for a detailed example of how to use the library programmatically to convert an Excel file to PDF.

License

Same as the original unoconv.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages