Skip to content

Python Integration

kudryavskiy_rv edited this page Jul 5, 2026 · 1 revision

Python Integration

Zero-dependency Python wrapper for office-print CLI.

Installation

Copy office_print.py into your project — no pip, no deps.

Quick start

from office_print import convert, convert_bytes

# File conversion
result = convert("report.docx", "report.pdf")
assert result.returncode == 0

# Bytes (in-memory)
with open("template.docx", "rb") as f:
    data = f.read()
result = convert_bytes(data, ".docx", "output.pdf")

# With options
result = convert(
    "report.docx", "report.pdf",
    format="jpeg", jpeg_quality=85,
    paper="a4", landscape=True,
    font_paths=["./fonts"],
)

API

convert(input_file, output_file=None, **kwargs)

Returns subprocess.CompletedProcess. Check result.returncode == 0.

Arg Type Default Description
input_file str | Path — .docx, .xlsx, .pptx
output_file str | Path None Output path
output_dir str | Path None Batch output dir
format str "pdf" "pdf", "png", "jpeg"
jpeg_quality int 92 1–100
paper str None "a4", "letter", "legal"
landscape bool False
font_paths list None Extra font dirs
sheets str None XLSX: "Sheet1,Data"
slides str None PPTX: "1-5"
streaming bool False Large XLSX
pdf_a bool False PDF/A-2b
tagged bool False Accessible PDF
pdf_ua bool False PDF/UA-1

convert_bytes(data, suffix, output_file=None, **kwargs)

Like convert() but for bytes. Uses temp file internally.

merge_pdfs(inputs, output)

Merge multiple PDFs into one.

split_pdf(input_pdf, output_dir, ranges)

Split PDF by page ranges. ranges = ["1-3", "5"].

Requirements

  • office-print binary on PATH or next to office_print.py

Clone this wiki locally