Repository navigation
Python Integration zh
kudryavskiy_rv edited this page Jul 5, 2026
·
1 revision
零依赖的 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"],
)返回 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() 类似但用于字节。使用临时文件。
将多个 PDF 合并为一个。
按页面范围拆分 PDF。ranges = ["1-3", "5"]。
-
office-print在 PATH 中或与office_print.py同目录
📖 English Docs