Skip to content

Python Integration ja

kudryavskiy_rv edited this page Jul 5, 2026 · 1 revision

Python 統合

office-print CLI のための依存性ゼロのラッパー。

インストール

office_print.py をプロジェクトにコピー — pip不要、依存性ゼロ。

クイックスタート

from office_print import convert, convert_bytes

# ファイル
result = convert("report.docx", "report.pdf")
assert result.returncode == 0

# バイト
with open("template.docx", "rb") as f:
    data = f.read()
result = convert_bytes(data, ".docx", "output.pdf")

# オプション付き
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)

subprocess.CompletedProcess を返す。

引数 型 デフォルト 説明
input_file str | Path — .docx、.xlsx、.pptx
output_file str | Path None 出力パス
output_dir str | Path None 一括出力ディレクトリ
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 追加フォントディレクトリ
sheets str None XLSX: "Sheet1,Data"
slides str None PPTX: "1-5"
streaming bool False 大規模 XLSX
pdf_a bool False PDF/A-2b
tagged bool False 構造化 PDF
pdf_ua bool False PDF/UA-1

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

convert() と同様だがバイト用。一時ファイルを使用。

merge_pdfs(inputs, output)

複数の PDF を一つにマージ。

split_pdf(input_pdf, output_dir, ranges)

ページ範囲で PDF を分割。ranges = ["1-3", "5"]。

要件

  • office-print が PATH 上または office_print.py と同じ場所に配置

Home-ja

Clone this wiki locally