Skip to main content

将 Pencil .pen 文件转换为 PowerPoint .pptx,通过 Pencil MCP server 获取精确布局

Project description

pencil2pptx

Pencil .pen 文件转换为 PowerPoint .pptx 文件。

通过 Pencil MCP server 获取精确的布局数据(坐标、尺寸由 Pencil 引擎计算),渲染为原生 PPT 元素(文本框、形状、图片),图标通过 PNG 导出保真插入。

安装

pip install pencil2pptx

使用

前提:Pencil 桌面应用需要正在运行。

# 基本用法(输出同名 .pptx)
pencil2pptx input.pen

# 指定输出路径
pencil2pptx input.pen -o output.pptx

# 调整字体缩放系数(默认 0.73)
pencil2pptx input.pen --font-scale 0.70

# 指定 Pencil MCP server 路径
pencil2pptx input.pen --pencil-cmd "/path/to/mcp-server"

uvx 免安装运行:

uvx pencil2pptx input.pen
uvx pencil2pptx input.pen -o output.pptx
uvx pencil2pptx input.pen --font-scale 0.70

python -m 运行:

python -m pencil2pptx input.pen -o output.pptx

参数

参数 说明 默认值
input 输入 .pen 文件路径 必填
-o, --output 输出 .pptx 路径 同名 .pptx
--font-scale 字体缩放系数 (Pencil px → PPT pt) 0.73
--pencil-cmd Pencil MCP server 可执行文件路径 Windows: %LOCALAPPDATA%\Programs\Pencil\...\mcp-server-windows-x64.exe

特性

Context Image 整体导出

当 Pencil 中的节点设置了 context 属性为 imageimg 时,该节点会被整体导出为 PNG 图片并直接插入 PPT,而不是逐子节点渲染。适用于复杂表格、图表等不适合拆解为原生 PPT 元素的内容。

在 Pencil 中设置方式:选中节点 → 设置 context 属性为 imageimg

页面顺序

导出的 PPT 页面顺序与 Pencil 画布上的视觉排列一致,按从上到下、从左到右排序。

工作原理

  1. 通过 MCP 协议连接正在运行的 Pencil 桌面应用
  2. 调用 snapshot_layout 获取 Pencil 引擎计算后的精确布局(坐标、尺寸)
  3. 按画布位置(先 y 后 x)排序顶层帧,确保页面顺序与 Pencil 视觉顺序一致
  4. 调用 batch_get 获取节点属性(类型、样式、文本内容等)
  5. 调用 export_nodesicon_font 节点导出为 4x 高清 PNG
  6. 检测 contextimage/img 的节点,整体导出为 2x PNG 图片
  7. 合并布局和属性数据,渲染为原生 PPT 元素(context image 节点直接以图片插入)

依赖

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pencil2pptx-0.2.2.tar.gz (256.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pencil2pptx-0.2.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pencil2pptx-0.2.2.tar.gz.

File metadata

  • Download URL: pencil2pptx-0.2.2.tar.gz
  • Upload date:
  • Size: 256.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for pencil2pptx-0.2.2.tar.gz
Algorithm Hash digest
SHA256 dab3c3763d78bdf31768f32ca2e342bf87aeab5e240f033a22c2814bfdfd7abd
MD5 7b5adf10c96f45e1861e803dbab74bf1
BLAKE2b-256 a6fd2510d01b538da204ab39715b5521e3aa461d537e211f73720bbbe53197d7

See more details on using hashes here.

File details

Details for the file pencil2pptx-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pencil2pptx-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for pencil2pptx-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7da1770d5602dfa25fab54a84e5524d9484e0d8682204cc68cb61f4ab2176489
MD5 4c8ca867c6c0f77a24c2d426b7a808a5
BLAKE2b-256 11acab8d1ef43c4d138c49454e878f6180c112c80a556cfdef62373a26219d21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page