[ SKILL_DOCUMENTATION ]
# PptxGenJS 教程
## 设置与基本结构
javascript
const pptxgen = require("pptxgenjs");
let pres = new pptxgen();
pres.layout = 'LAYOUT_16x9'; // 或 'LAYOUT_16x10', 'LAYOUT_4x3', 'LAYOUT_WIDE'
pres.author = '你的名字';
pres.title = '演示文稿标题';
let slide = pres.addSlide();
slide.addText("Hello World!", { x: 0.5, y: 0.5, fontSize: 36, color: "363636" });
pres.writeFile({ fileName: "Presentation.pptx" });
## 布局尺寸
幻灯片尺寸(坐标单位为英寸):
- `LAYOUT_16x9`: 10" × 5.625" (默认)
- `LAYOUT_16x10`: 10" × 6.25"
- `LAYOUT_4x3`: 10" × 7.5"
- `LAYOUT_WIDE`: 13.3" × 7.5"
---
## 文本与格式
javascript
// 基本文本
slide.addText("简单文本", {
x: 1, y: 1, w: 8, h: 2, fontSize: 24, fontFace: "Arial",
color: "363636", bold: true, align: "center", valign: "middle"
});
// 字符间距 (使用 charSpacing,letterSpacing 会被静默忽略)
slide.addText("间距文本", { x: 1, y: 1, w: 8, h: 1, charSpacing: 6 });
// 富文本数组
slide.addText([
{ text: "粗体 ", options: { bold: true } },
{ text: "斜体 ", options: { italic: true } }
], { x: 1, y: 3, w: 8, h: 1 });
// 多行文本 (需要 breakLine: true)
slide.addText([
{ text: "第一行", options: { breakLine: true } },
{ text: "第二行", options: { breakLine: true } },
{ text: "第三行" } // 最后一项不需要 breakLine
], { x: 0.5, y: 0.5, w: 8, h: 2 });
// 文本框边距 (内部填充)
slide.addText("标题", {
x: 0.5, y: 0.3, w: 9, h: 0.6,
margin: 0 // 当文本需要与其他元素(如形状或图标)对齐时使用 0
});
**提示:** 文本框默认有内部边距。当需要文本与相同 x 位置的形状、线条或图标精确对齐时,请设置 `margin: 0`。
---
## 列表与项目符号
javascript
// ✅ 正确: 多个项目符号
slide.addText([
{ text: "第一项", options: { bullet: true, breakLine: true } },
{ text: "第二项", options: { bullet: true, breakLine: true } },
{ text: "第三项", options: { bullet: true } }
], { x: 0.5, y: 0.5, w: 8, h: 3 });
// ❌ 错误: 切勿使用 Unicode 项目符号
slide.addText("• 第一项", { ... }); // 会创建双重项目符号
// 子项和编号列表
{ text: "子项", options: { bullet: true, indentLevel: 1 } }
{ text: "第一", options: { bullet: { type: "number" }, breakLine: true } }
## 形状
javascript
slide.addShape(pres.shapes.RECTANGLE, {
x: 0.5, y: 0.8, w: 1.5, h: 3.0,
fill: { color: "F