Converter setup
rtflite can convert RTF documents to PDF using LibreOffice. This guide shows how to install and use LibreOffice for PDF conversion.
Install LibreOffice
On macOS (using Homebrew):
brew install --cask libreoffice
On Ubuntu/Debian:
sudo apt-get install libreoffice
On Windows (using Chocolatey):
choco install libreoffice
Tip
After installation, restart your shell to ensure PATH updates are loaded
so that rtflite can find LibreOffice.
Using the converter
Once LibreOffice is installed, convert RTF files to PDF in your code:
import rtflite as rtf
# Create your RTF document
doc = rtf.RTFDocument(df=df, ...)
doc.write_rtf("output.rtf")
# Convert to PDF
try:
converter = rtf.LibreOfficeConverter()
converter.convert(
input_files="output.rtf",
output_dir=".",
format="pdf",
overwrite=True
)
print("PDF created successfully!")
except FileNotFoundError:
print("LibreOffice not found. Please install it for PDF conversion.")
Custom installation paths
If LibreOffice is installed in a non-standard location, you can specify the path:
converter = rtf.LibreOfficeConverter(
executable_path="/custom/path/to/soffice"
)
Supported output formats
Besides PDF, LibreOffice can convert RTF to:
docx- Microsoft Word formathtml- HTML formatodt- OpenDocument Text format
Example:
converter.convert(input_files="output.rtf", output_dir=".", format="docx")
Batch conversion
Convert multiple RTF files at once:
files = ["file1.rtf", "file2.rtf", "file3.rtf"]
converter = rtf.LibreOfficeConverter()
converter.convert(
input_files=files,
output_dir="pdfs/",
format="pdf",
overwrite=True
)
CI/CD integration
For automated workflows:
GitHub Actions
- name: Install LibreOffice
run: |
sudo apt-get update
sudo apt-get install -y libreoffice
Docker
FROM python:3.14
RUN apt-get update && apt-get install -y libreoffice
Troubleshooting
"Can't find LibreOffice executable" error
- Ensure LibreOffice is installed
- Restart your terminal/IDE
- Check if
sofficeis in your PATH: - macOS/Linux:
which soffice - Windows:
where soffice - If not in PATH, specify the full path when creating the converter
Version requirements
Minimum version requirement
rtflite requires LibreOffice version 7.1 or higher. Check your version:
soffice --version
Performance tips
Optimization suggestions
- LibreOffice starts a background process for conversions.
- For batch conversions, reuse the same converter instance.
- The first conversion may be slower as LibreOffice initializes.
- Consider using thread-based parallel processing for large batches.