HTML 转 PPTX 形状转换器 — 将 HTML 幻灯片转换为完全可编辑的 PPTX,自动内嵌外部 CSS,保留 CSS 样式、布局,映射为 PPTX 原生形状(矩形/文本框/图片等)
将 HTML 幻灯片转换为 完全可编辑的 PPTX,核心特性:
<link> 引用的 CSS 文件嵌入到 <style> 标签bash
cd /Users/panda/.openclaw/workspace/skills/html2pptx-shape
pip3 install -r requirements.txt
playwright install chromium
bash
# 转换 HTML 文件(自动内嵌外部 CSS)
python3 index.py <input.html> [output.pptx]
# 示例
python3 index.py examples/demo.html
python3 index.py my-presentation.html my-output.pptx
项目说明文件名<input>_converted.pptx(默认)或指定名称格式PPTX (Office Open XML)比例16:9 widescreen可编辑性✅ 所有文字/形状可编辑
自动将外部 CSS 文件嵌入到 HTML 的 <style> 标签中:
html
<!-- 转换前 -->
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="theme.css">
<!-- 转换后 -->
<style>
/* styles.css 内容 */
/* theme.css 内容 */
</style>
支持:
<link> 标签:root 和任何选择器中的定义)CSS 属性PPTX 映射支持度color文字颜色✅background-color填充颜色✅background (gradient)渐变填充⚠️ 转为纯色font-family字体✅font-size字号✅font-weight字重✅text-align对齐方式✅border边框✅border-radius圆角矩形✅box-shadow阴影✅opacity透明度✅width/height尺寸✅position: absolute绝对定位✅
HTML 元素PPTX 形状说明<div>Rectangle矩形背景/容器<p>, <h1>- <h6>TextBox文本框,保留字体/颜色/对齐<img>Picture图片,支持 base64/URL/本地文件<svg>FreeformSVG 路径转 PPTX 自由形状(简化)<span>(内联)文本格式化,不创建独立形状<ul>, <ol>TextBox列表文本框,保留项目符号
<style> 标签section.slide,每页创建一张幻灯片html-ppt 生成的 HTML 演示文稿转为可编辑 PPTXbash
python3 index.py examples/demo.html
# 输出:examples/demo_converted.pptx
bash
python3 index.py my-presentation.html
# 自动嵌入 style.css, theme.css 等外部文件
# 输出:my-presentation_converted.pptx
bash
python3 index.py input.html output.pptx
python
from index import run
result = run(["./examples/demo.html"])
print(f"Generated: {result['output_file']}")
print(f"Slides: {result['slides_count']}")
text
html2pptx-shape/
├── SKILL.md (本文档)
├── README.md (快速入门)
├── index.py (核心转换逻辑)
├── requirements.txt (Python 依赖)
├── scripts/
│ ├── embed-css.py (独立 CSS 嵌入工具)
│ ├── debug-convert.py (调试脚本)
│ ├── check-inline.py (样式检查脚本)
│ └── debug-vars.py (变量调试脚本)
└── examples/
├── demo.html (示例 HTML - 4 页)
├── demo_converted.pptx (生成的 PPTX)
├── external-css.html (外部 CSS 测试)
├── external-css_converted.pptx
├── styles.css
└── theme.css
bash
# 1. 用 html-ppt 生成 HTML 演示文稿
# (使用 html-ppt skill 创建 HTML)
# 2. 转换为可编辑 PPTX
python3 index.py my-deck/index.html
# 3. 在 PowerPoint 中打开并编辑
open my-deck/index_converted.pptx
bash
# 情况 A: HTML 引用外部 CSS
# index.html 中有:<link rel="stylesheet" href="style.css">
# 直接转换,自动嵌入 CSS
python3 index.py index.html
# 情况 B: 想先内嵌 CSS 再转换
python3 scripts/embed-css.py index.html
python3 index.py index_embedded.html
限制说明建议CSS 动画不支持(转换为静态)使用截图版保留视觉效果CSS Grid/Flex简化为绝对定位检查布局是否正确外部字体回退到系统字体确保系统有相应字体::before/ ::afterPPTX 不支持伪元素忽略警告background-clip: text渐变文字转纯色手动在 PPTX 中添加渐变复杂 SVG降级为占位符简化 SVG 或转为图片
bash
# Python 依赖
pip3 install python-pptx beautifulsoup4 pillow requests cssutils premailer
# Playwright 浏览器(用于截图功能)
playwright install chromium
text
⚠️ CSS file not found: xxx.css
原因: 相对路径无法解析
解决:
scripts/embed-css.py 先内嵌 CSS<style> 标签中原因: CSS 选择器太复杂或使用了不支持的属性
解决:
style="..." 替代原因: CSS Grid/Flex 布局被简化
解决:
position: absolute 替代特性html2pptx-shapehtml-to-pptxCSS 内嵌✅ 自动⚠️ 需要预处理器CSS 变量解析✅ 完整支持⚠️ 部分支持形状映射✅ 原生 PPTX 形状⚠️ 简化文本框可编辑性✅ 完全可编辑✅ 完全可编辑文件大小小 (30-50KB)小 (30-50KB)截图高保真❌✅ 支持
MIT
老 6 🎯