mcpField
S
skill-pdf-to-pptx-tool

skill-pdf-to-pptx-tool

github.com/dnvriend文档处理2367 次安装47 周前更新
代码仓库

关于 skill-pdf-to-pptx-tool

skill-pdf-to-pptx-tool 介绍如何使用命令行工具将 PDF 转为 PowerPoint,适合需要制作演示稿或批量处理文档的用户。它支持调节渲染分辨率,并提供分级日志以排查问题。

主要功能

  1. 01将 PDF 页面转为幻灯片
  2. 02自定义转换 DPI
  3. 03分级详细程度日志
  4. 04生成 bash、zsh、fish 补全

适用场景

  1. 01把 PDF 报告转换为演示文稿
  2. 02通过 DPI 调整画面质量与文件大小
  3. 03排查转换失败或速度问题

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dnvriend/pdf-to-pptx-tool --skill skill-pdf-to-pptx-tool

安装后在 Claude Code 中输入/skill-pdf-to-pptx-tool确认已加载。

详细介绍

适用场景

  • 将 PDF 文档转换为可编辑的 PowerPoint 演示文稿
  • 根据 PDF 报告或文档创建幻灯片
  • 需要使用自定义 DPI 进行高质量的 PDF 到 PPTX 转换
  • 需要使用多级详细程度日志来调试转换

PDF 转 PowerPoint 转换器技能

用途

本技能全面介绍如何使用 pdf-to-pptx-tool,这是一款专业的 CLI 工具,可将 PDF 文档转换为 PowerPoint 演示文稿。每个 PDF 页面都会转换为一张高质量幻灯片,且分辨率可自定义。

适用场景

在以下情况下使用此技能:

  • 需要将 PDF 文档转换为 PowerPoint 格式
  • 想要自定义转换质量(DPI 设置)
  • 需要通过详细日志调试转换问题
  • 处理多页 PDF 文档
  • 需要在工作流中以编程方式将 PDF 转换为 PPTX

以下情况请勿使用此技能:

  • 编辑现有 PowerPoint 文件(请直接使用 PowerPoint)
  • 将其他格式(图像、Word 文档)转换为 PPTX
  • 从 PDF 中提取文本(请使用 PDF 文本提取工具)
  • 从头创建 PowerPoint 演示文稿(请使用 PowerPoint 或 python-pptx)

CLI 工具:pdf-to-pptx-tool

这是一款基于 Click 构建的现代 Python CLI 工具,提供多级详细程度日志、Shell 补全和类型安全代码。

安装
# Clone the repository
git clone https://github.com/dnvriend/pdf-to-pptx-tool.git
cd pdf-to-pptx-tool

# Install globally with uv
uv tool install .
先决条件
  • Python 3.14+
  • poppler 系统库(用于 PDF 渲染)
    • macOS:brew install poppler
    • Ubuntu/Debian:apt-get install poppler-utils
    • Windows:从 poppler releases 下载
快速开始
# Basic conversion
pdf-to-pptx-tool convert document.pdf slides.pptx

# High quality (300 DPI)
pdf-to-pptx-tool convert report.pdf presentation.pptx --dpi 300

# With verbose logging
pdf-to-pptx-tool -v convert input.pdf output.pptx

渐进式展开

📖 核心命令(点击展开)
convert - 将 PDF 转换为 PowerPoint

将 PDF 文档转换为 PowerPoint 格式,并为每个 PDF 页面创建一张幻灯片;画质设置可自定义。

用法:

pdf-to-pptx-tool convert INPUT_PDF OUTPUT_PPTX [OPTIONS]

参数:

  • INPUT_PDF:输入 PDF 文件的路径(必需)
    • 文件必须存在且为有效的 PDF 文件
    • 支持任意 PDF 版本
    • 大小不限(取决于可用内存)
  • OUTPUT_PPTX:输出 PowerPoint 文件的路径(必需)
    • 如果文件已存在,则会覆盖;否则会新建
    • 扩展名应为 .pptx
    • 父目录必须存在
  • --dpi INTEGER:页面转换分辨率(可选)
    • 默认值:200 DPI(画质良好,文件大小适中)
    • 范围:72–600 DPI
    • DPI 越高,画质越好,但文件越大
    • 建议值:用于演示文稿时为 200–300
  • -v, --verbose:多级详细程度
    • 不添加标志:仅显示警告和错误
    • -v:INFO 级别(操作和进度)
    • -vv:DEBUG 级别(详细步骤)
    • -vvv:TRACE 级别(库内部信息)

示例:

# Example 1: Basic conversion (default 200 DPI)
pdf-to-pptx-tool convert quarterly-report.pdf q4-presentation.pptx

# Example 2: High quality for detailed diagrams
pdf-to-pptx-tool convert technical-diagram.pdf slides.pptx --dpi 300

# Example 3: Lower quality for quick preview
pdf-to-pptx-tool convert draft.pdf preview.pptx --dpi 150

# Example 4: With INFO logging to see progress
pdf-to-pptx-tool -v convert large-doc.pdf output.pptx

# Example 5: With DEBUG logging for troubleshooting
pdf-to-pptx-tool -vv convert problematic.pdf fixed.pptx

# Example 6: Batch conversion with shell loop
for pdf in *.pdf; do
  pdf-to-pptx-tool convert "$pdf" "${pdf%.pdf}.pptx"
done

输出:

  • 在指定路径创建 PowerPoint 文件
  • 幻灯片属性:
    • 宽高比:16:9(宽屏)
    • 尺寸:10" × 5.625"
    • 布局:每个 PDF 页面对应一张铺满幻灯片的图像
    • 背景:透明
  • 控制台输出:
    • 成功:"✓ Successfully converted input.pdf to output.pptx"
    • 错误:"✗ Error: [detailed error message]"
  • 退出代码:
    • 0:成功
    • 1:错误(文件不存在、输入无效或转换失败)

completion - 生成 Shell 补全脚本

为 bash、zsh 或 fish Shell 生成 Shell 补全脚本。

用法:

pdf-to-pptx-tool completion SHELL

参数:

  • SHELL:Shell 类型(必需)
    • 选项:bash、zsh、fish
    • 不区分大小写

示例:

# Generate bash completion
eval "$(pdf-to-pptx-tool completion bash)"

# Generate zsh completion
eval "$(pdf-to-pptx-tool completion zsh)"

# Generate fish completion
pdf-to-pptx-tool completion fish | source

# Save to file for permanent installation
pdf-to-pptx-tool completion bash > ~/.pdf-to-pptx-tool-completion.bash
echo 'source ~/.pdf-to-pptx-tool-completion.bash' >> ~/.bashrc

输出: 将对应 Shell 的补全脚本打印到 stdout。

⚙️ 高级功能(点击展开) ### 多级详细程度日志

该工具支持逐级提高日志详细程度,用于调试和监控转换过程。

日志级别:

标志级别输出使用场景
(无)WARNING仅显示错误/警告生产环境、安静模式
-vINFO+ 操作、进度常规调试
-vvDEBUG+ 详细步骤、文件大小开发、故障排查
-vvvTRACE+ 库内部信息(pdf2image、PIL、pptx)深度调试

示例:

# Quiet mode - only see errors
pdf-to-pptx-tool convert input.pdf output.pptx

# INFO - see conversion progress
pdf-to-pptx-tool -v convert input.pdf output.pptx
# Output:
# [INFO] Starting PDF to PPTX conversion
# [INFO] Converting input.pdf to output.pptx (DPI: 200)
# [INFO] Converting PDF pages to images...
# [INFO] Converted 5 pages
# [INFO] Creating PowerPoint presentation...
# [INFO] Saving presentation to output.pptx

# DEBUG - see detailed processing
pdf-to-pptx-tool -vv convert input.pdf output.pptx
# Additional output:
# [DEBUG] Input: input.pdf, Output: output.pptx, DPI: 200
# [DEBUG] Validating input file: input.pdf
# [DEBUG] Input file size: 2.45 MB
# [DEBUG] Using DPI setting: 200
# [DEBUG] Processing slide 1/5
# [DEBUG] Output file size: 8.23 MB

# TRACE - see library internals
pdf-to-pptx-tool -vvv convert input.pdf output.pptx
# Shows pdf2image, PIL, and pptx library debug messages
DPI 质量指南

根据使用场景选择 DPI:

DPI质量文件大小最适合
72低最小快速预览、幻灯片草稿
150中小网页演示、电子邮件
200良好中默认值——适用于大多数场景
300高大印刷质量、详细图表
600极高极大专业印刷、海报

权衡:

  • 较高 DPI:质量更好、文件更大、转换更慢
  • 较低 DPI:转换更快、文件更小、质量更低
  • 最佳平衡点:大多数演示文稿使用 200-300 DPI
批量处理

高效处理多个 PDF:

# Convert all PDFs in directory
for pdf in *.pdf; do
  echo "Converting $pdf..."
  pdf-to-pptx-tool convert "$pdf" "${pdf%.pdf}.pptx"
done

# With custom DPI
for pdf in *.pdf; do
  pdf-to-pptx-tool convert "$pdf" "${pdf%.pdf}.pptx" --dpi 300
done

# With error handling
for pdf in *.pdf; do
  if pdf-to-pptx-tool -v convert "$pdf" "${pdf%.pdf}.pptx"; then
    echo "✓ Converted $pdf"
  else
    echo "✗ Failed to convert $pdf"
  fi
done
Shell 补全

启用 Tab 补全,加快操作:

# Bash - add to ~/.bashrc
eval "$(pdf-to-pptx-tool completion bash)"

# Zsh - add to ~/.zshrc
eval "$(pdf-to-pptx-tool completion zsh)"

# Fish - save to completions directory
mkdir -p ~/.config/fish/completions
pdf-to-pptx-tool completion fish > ~/.config/fish/completions/pdf-to-pptx-tool.fish

优点:

  • 补全命令:pdf-to-pptx-tool <TAB>
  • 补全选项:pdf-to-pptx-tool convert --<TAB>
  • 自动补全文件路径
🔧 故障排查(点击展开)
常见问题

问题:“poppler not found”或 PDF 转换失败

# Symptom
RuntimeError: Failed to convert PDF pages: poppler not found

解决方案: 安装 poppler 系统库:

# macOS
brew install poppler

# Ubuntu/Debian
sudo apt-get install poppler-utils

# Fedora
sudo dnf install poppler-utils

# Verify installation
pdftoppm -v

问题:“File not found”错误

# Symptom
✗ Error: Input PDF file not found: document.pdf

解决方案:

  • 确认文件路径正确
  • 必要时使用绝对路径
  • 检查文件权限
# Check file exists
ls -l document.pdf

# Use absolute path
pdf-to-pptx-tool convert /full/path/to/document.pdf output.pptx

问题:输出文件过大

# Symptom
Generated 50MB PPTX from 2MB PDF

解决方案: 降低 DPI 设置:

# Try lower DPI
pdf-to-pptx-tool convert input.pdf output.pptx --dpi 150

# Or use default 200 DPI
pdf-to-pptx-tool convert input.pdf output.pptx

问题:PowerPoint 中的图像看起来模糊

# Symptom
Text and diagrams appear pixelated

解决方案: 提高 DPI 设置:

# Use higher quality
pdf-to-pptx-tool convert input.pdf output.pptx --dpi 300

# For print quality
pdf-to-pptx-tool convert input.pdf output.pptx --dpi 600

问题:转换速度非常慢

# Symptom
Large PDF takes minutes to convert

解决方案:

  1. 使用 DEBUG 日志查看进度:
pdf-to-pptx-tool -vv convert large.pdf output.pptx
  1. 考虑降低 DPI 以加快转换:
pdf-to-pptx-tool convert large.pdf output.pptx --dpi 150
  1. 将大型 PDF 拆分成多个部分,分别转换

问题:写入输出文件时权限被拒绝

# Symptom
PermissionError: [Errno 13] Permission denied: 'output.pptx'

解决方案:

  • 检查目录写入权限
  • 使用其他输出位置
# Write to home directory
pdf-to-pptx-tool convert input.pdf ~/output.pptx

# Or create directory first
mkdir -p output-dir
pdf-to-pptx-tool convert input.pdf output-dir/output.pptx
获取帮助
# Tool help
pdf-to-pptx-tool --help

# Command help
pdf-to-pptx-tool convert --help

# Completion help
pdf-to-pptx-tool completion --help

# Version info
pdf-to-pptx-tool --version
调试工作流

转换失败时,请使用以下调试工作流:

# 1. Check file exists and is readable
ls -lh document.pdf
file document.pdf

# 2. Verify poppler is installed
pdftoppm -v

# 3. Try with DEBUG logging
pdf-to-pptx-tool -vv convert document.pdf test.pptx

# 4. Try with lower DPI if memory issues
pdf-to-pptx-tool -vv convert document.pdf test.pptx --dpi 150

# 5. Check Python and dependencies
python --version
pdf-to-pptx-tool --version

退出代码

  • 0:成功 - 转换已成功完成
  • 1:错误 - 文件未找到、输入无效、转换失败或权限被拒绝

输出格式

默认 PowerPoint 输出:

  • 格式:Office Open XML (.pptx)
  • 宽高比:16:9 宽屏
  • 幻灯片尺寸:10 英寸 × 5.625 英寸
  • 布局:每页 PDF 对应一张全幅幻灯片图像
  • 图像格式:嵌入幻灯片的 PNG
  • 兼容性:PowerPoint 2007+(Windows/Mac/Online)

控制台输出:

# Success
✓ Successfully converted document.pdf to slides.pptx

# Error
✗ Error: Input PDF file not found: document.pdf

日志输出(使用 -v/-vv/-vvv 时):

[INFO] Starting PDF to PPTX conversion
[INFO] Converting document.pdf to slides.pptx (DPI: 200)
[DEBUG] Input file size: 2.45 MB
[INFO] Converted 10 pages
[DEBUG] Output file size: 12.78 MB
[INFO] Conversion completed successfully

最佳实践

  1. 从默认 DPI(200)开始:在质量和文件大小之间取得良好平衡
  2. 调试时使用详细日志:-vv 可显示详细的转换步骤
  3. 先用示例 PDF 测试:批量处理前先确认质量
  4. 监控输出文件大小:如果文件过大,请调整 DPI
  5. 高效批量处理:使用 Shell 循环处理多个文件
  6. 启用 Shell 补全:加快命令行操作
  7. 保持 poppler 更新:确保兼容最新的 PDF 功能
  8. 使用绝对路径:避免相对路径带来的混淆
  9. 验证前置条件:批量转换前检查 poppler 是否已安装
  10. 妥善处理错误:在脚本中检查退出代码

资源

  • GitHub 仓库:https://github.com/dnvriend/pdf-to-pptx-tool
  • Python 依赖项:
    • pdf2image(PDF 转图像)
    • python-pptx(创建 PowerPoint 文件)
    • Pillow(图像处理)
    • Click(命令行框架)
  • 系统依赖项:poppler(PDF 渲染引擎)
  • 相关工具:
    • PyPDF2(提取 PDF 文本)
    • ReportLab(生成 PDF)
    • pandoc(通用文档转换器)

评论

支持 Markdown