Converting Word documents to PDF from Python usually means installing LibreOffice on your server,
running soffice --headless in a subprocess, and cleaning up temp files. With the Ink & Order API it is one requests.post.
Get a free key (50 files/month), then export it:
export INKORDER_API_KEY=io_live_...
pip install requests
"""Convert every .docx in a folder to PDF with the Ink & Order API.
Usage: INKORDER_API_KEY=io_live_... python guide_docx_to_pdf.py ./contracts
"""
import os
import sys
from pathlib import Path
import requests
BASE = os.environ.get("INKORDER_API_URL", "https://api.inkandordertools.com")
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['INKORDER_API_KEY']}"
def docx_to_pdf(src: Path) -> Path:
with src.open("rb") as f:
r = session.post(f"{BASE}/v1/convert", files={"file": (src.name, f)}, timeout=120)
r.raise_for_status()
dst = src.with_suffix(".pdf")
dst.write_bytes(r.content)
return dst
folder = Path(sys.argv[1] if len(sys.argv) > 1 else ".")
for docx in sorted(folder.glob("*.docx")):
print(f"{docx.name} -> {docx_to_pdf(docx).name}")
python guide_docx_to_pdf.py ./contracts
# offer.docx -> offer.pdf
file; the .docx extension routes it to LibreOffice..doc, .odt, .rtf, .xlsx and .pptx work the same way.429 (quota) and 502 (corrupt input) explicitly — see errors.