Skip to content

wonphen-coder/document-reformatter

Repository files navigation

document-reformatter - 多格式文档自动排版与转换工具

这是一个完整的文档转换和排版技能,支持多种格式互转和专业模板应用。

快速开始

1. 安装依赖

cd C:\Users\wonph\.workbuddy\skills\document-reformatter
pip install -r requirements.txt

另外需要安装 pandoc:https://pandoc.org/installing.html

2. 验证安装

python workbuddy_entry.py --help

3. 基本使用

Python API

from 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(支持模板应用)
  • PDF
  • 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/                   # 输出目录

转换流程

  1. DOC 转 DOCX(如需要)
  2. 提取图片
  3. 转换为 Markdown(智能选择引擎)
  4. 清洗 Markdown
  5. 清洗表格
  6. 处理图片引用
  7. 应用模板并转换
  8. 输出文件

高级用法

进度回调

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"
)

常见问题

Q: 转换失败怎么办?

A: 检查以下几点:

  1. pandoc 是否正确安装(运行 pandoc --version
  2. 依赖是否完整安装(运行 pip install -r requirements.txt
  3. 输入文件是否损坏

Q: PDF 转换效果不好?

A: 可以安装 Marker 引擎提升 PDF 转换质量:

pip install marker-pdf

Q: DOC 文件无法转换?

A: Windows 系统需要安装 Microsoft Word,非 Windows 系统需要安装 LibreOffice。

更多信息

详细使用说明请参考 SKILL.md 文件。

About

A document formatting tool for converting Markdown/PDF/DOCX to styled DOCX with templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages