这是一个完整的文档转换和排版技能,支持多种格式互转和专业模板应用。
cd C:\Users\wonph\.workbuddy\skills\document-reformatter
pip install -r requirements.txt另外需要安装 pandoc:https://pandoc.org/installing.html
python workbuddy_entry.py --helpfrom workbuddy_entry import process_document
result = process_document(
input_file="test.pdf",
output_format="docx",
template_name="技术方案排版模板"
)
if result['success']:
print(f"输出文件: {result['output_file']}")
else:
print(f"错误: {result['error']}")# 基本用法
python workbuddy_entry.py test.pdf docx 技术方案排版模板
# 指定输出格式
python workbuddy_entry.py test.docx pdf 机关公文排版模板
# 使用自定义模板
python workbuddy_entry.py test.pdf docx --template-path custom_template.docx- PDF(需要 Marker 或 markitdown)
- DOCX
- DOC(Windows 需要 Word,其他系统需要 LibreOffice)
- ODT
- RTF
- EPUB
- HTML
- PPTX
- XLSX
- DOCX(支持模板应用)
- ODT
- HTML
- Markdown
- EPUB
- LaTeX
- PPTX
| 模板名称 | 适用场景 |
|---|---|
| 技术方案排版模板 | 技术方案、商务报告、投标文件 |
| 机关公文排版模板 | 通知、请示、函、报告、纪要 |
| 专硕论文排版模板 | 专业硕士论文、学位论文 |
document-reformatter/
├── SKILL.md # 技能说明文件
├── README.md # 本文件
├── requirements.txt # Python 依赖
├── workbuddy_entry.py # Workbuddy 入口脚本
├── scripts/ # 核心脚本
│ ├── __init__.py
│ ├── core_converter.py # 核心转换逻辑
│ ├── document_handler.py # 文档处理
│ ├── clean_md.py # Markdown 清洗
│ ├── table_cleaner.py # 表格清洗
│ ├── table_handler.py # 表格处理
│ ├── image_handler.py # 图片处理
│ ├── cache_handler.py # 缓存处理
│ └── infer_style_from_text.py # 样式推断
├── references/ # 模板文件
│ ├── 技术方案排版模板.docx
│ ├── 机关公文排版模板.docx
│ └── 专硕论文排版模板.docx
└── output/ # 输出目录
- DOC 转 DOCX(如需要)
- 提取图片
- 转换为 Markdown(智能选择引擎)
- 清洗 Markdown
- 清洗表格
- 处理图片引用
- 应用模板并转换
- 输出文件
def my_progress(msg):
print(f"[{msg}]")
result = process_document(
input_file="test.pdf",
output_format="docx",
progress_callback=my_progress
)from workbuddy_entry import batch_process
files = ["doc1.pdf", "doc2.docx", "doc3.odt"]
results = batch_process(
input_files=files,
output_format="docx",
template_name="技术方案排版模板",
progress_callback=print
)result = process_document(
input_file="test.pdf",
output_format="docx",
custom_template_path="path/to/your/template.docx"
)A: 检查以下几点:
- pandoc 是否正确安装(运行
pandoc --version) - 依赖是否完整安装(运行
pip install -r requirements.txt) - 输入文件是否损坏
A: 可以安装 Marker 引擎提升 PDF 转换质量:
pip install marker-pdfA: Windows 系统需要安装 Microsoft Word,非 Windows 系统需要安装 LibreOffice。
详细使用说明请参考 SKILL.md 文件。