PPTX
演示文稿属性
设置核心、扩展和自定义属性、幻灯片分节,以及演示文稿级别设置
核心属性
核心元数据写入 docProps/core.xml,并在解析时读回。直接在演示文稿选项上设置这些字段:
{
"title": "季度回顾",
"subject": "财务",
"creator": "张三",
"keywords": "q4, 回顾",
"description": "季度业务回顾",
"revision": 2,
"slides": []
}
import { generatePresentation } from "@office-open/pptx";
const buffer = await generatePresentation({
title: "季度回顾",
subject: "财务",
creator: "张三",
keywords: "q4, 回顾",
description: "季度业务回顾",
revision: 2,
slides: [
/* … */
],
});
| 属性 | 类型 | 说明 |
|---|---|---|
title | string | 演示文稿标题 |
subject | string | 主题 |
creator | string | 作者 |
keywords | string | 关键词 |
description | string | 描述 |
lastModifiedBy | string | 最后修改者 |
revision | number | 修订号 |
lastPrinted | string | 最后打印日期(W3CDTF) |
created | string | 创建日期(W3CDTF) |
modified | string | 最后修改日期(W3CDTF) |
扩展属性
appProperties 写入 docProps/app.xml。常用可设置字段为 template、manager、company 和 application;其余(slides、notes、totalTime 等)是通常由 Office 计算的文档统计信息:
{
"appProperties": { "company": "Globex", "manager": "张三" },
"slides": []
}
import { generatePresentation } from "@office-open/pptx";
const buffer = await generatePresentation({
appProperties: {
company: "Globex",
manager: "张三",
template: "report.potx",
application: "office-open",
},
slides: [
/* … */
],
});
| 属性 | 类型 | 说明 |
|---|---|---|
template | string | 模板名称 |
manager | string | 经理名称 |
company | string | 公司名称 |
application | string | 应用程序名称 |
appVersion | string | 应用程序版本 |
slides | number | 幻灯片数 |
notes | number | 备注数 |
hiddenSlides | number | 隐藏幻灯片数 |
totalTime | number | 总编辑时间(分钟) |
hyperlinkBase | string | 超链接基础 URL |
docSecurity | number | 文档安全级别 |
自定义属性
customProperties 写入 docProps/custom.xml。每个值都是字符串:
{
"customProperties": [
{ "name": "ProjectId", "value": "PRJ-42" },
{ "name": "Department", "value": "Finance" }
],
"slides": []
}
import { generatePresentation } from "@office-open/pptx";
const buffer = await generatePresentation({
customProperties: [
{ name: "ProjectId", value: "PRJ-42" },
{ name: "Department", value: "Finance" },
],
slides: [
/* … */
],
});
| 属性 | 类型 | 说明 |
|---|---|---|
name | string | 属性名称 |
value | string | 属性值 |
幻灯片分节
将幻灯片按命名分节。共享同一 section 名称的幻灯片在 PowerPoint 导航窗格中构成一节(presentation.xml 中的 p14:sectionLst);未设置 section 的幻灯片保持未分组:
{
"slides": [
{ "section": "导言", "children": [] },
{ "section": "导言", "children": [] },
{ "section": "正文", "children": [] }
]
}
import { generatePresentation } from "@office-open/pptx";
const buffer = await generatePresentation({
slides: [
{
section: "导言",
children: [
/* … */
],
},
{
section: "导言",
children: [
/* … */
],
},
{
section: "正文",
children: [
/* … */
],
},
],
});
分节支持经 parsePresentation 往返——每张幻灯片的 section 会被读回。
演示文稿设置
设置演示文稿的根属性(服务器缩放、起始幻灯片编号、RTL 等):
{
"firstSlideNum": 1,
"rtl": false,
"autoCompressPictures": true,
"bookmarkIdSeed": 1234,
"slides": [
{
"children": [
{ "shape": { "textBody": { "children": ["Presentation with custom settings"] } } }
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
firstSlideNum: 1,
rtl: false,
autoCompressPictures: true,
bookmarkIdSeed: 1234,
slides: [
{
children: [{ shape: { textBody: { text: "Presentation with custom settings" } } }],
},
],
});
根属性
| 选项 | 类型 | 说明 |
|---|---|---|
serverZoom | string | 服务器缩放级别 |
firstSlideNum | number | 起始幻灯片编号 |
showSpecialPlsOnTitleSld | boolean | 在标题幻灯片上显示占位符 |
rtl | boolean | 从右到左布局 |
removePersonalInfoOnSave | boolean | 保存时移除个人信息 |
compatMode | boolean | 兼容模式 |
strictFirstAndLastChars | boolean | 严格的首尾字符规则 |
embedTrueTypeFonts | boolean | 嵌入 TrueType 字体 |
saveSubsetFonts | boolean | 保存字体子集 |
autoCompressPictures | boolean | 自动压缩图片 |
bookmarkIdSeed | number | 书签 ID 种子 |
conformance | string | "strict" 或 "transitional" |
修改保护
使用密码保护演示文稿免受修改。当提供 password 时,会自动计算 SHA-512 哈希(随机盐值,100,000 次迭代):
{
"modifyVerifier": {
"password": "secret"
},
"slides": [
{
"children": [{ "shape": { "textBody": { "children": ["Protected presentation"] } } }]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
modifyVerifier: {
password: "secret",
},
slides: [
{
children: [{ shape: { textBody: { text: "Protected presentation" } } }],
},
],
});
修改验证选项
| 选项 | 类型 | 说明 |
|---|---|---|
password | string | 明文密码(自动哈希) |
algorithmName | string | 哈希算法(默认:"SHA-512") |
hashValue | string | Base64 编码的密码哈希 |
saltValue | string | Base64 编码的盐值 |
spinValue | number | Spin 值 |
spinCount | number | 哈希迭代次数 |
cryptoProviderType | string | 加密提供程序类型 |
cryptoAlgorithmClass | string | 算法类别 |
cryptoAlgorithmType | string | 算法类型 |
cryptoAlgorithmSid | number | 算法 SID |
cryptoProvider | string | 加密提供程序 |
saltData | string | Base64 编码的盐数据 |
hashData | string | Base64 编码的哈希数据 |
algorithmExtensionId | number | 算法扩展 ID |
algorithmExtensionSource | string | 算法扩展来源 |
cryptoProviderTypeExtension | number | 加密提供程序类型扩展 |
cryptoProviderTypeExtensionSource | string | 加密提供程序类型扩展来源 |
视图属性
配置演示文稿打开时的显示方式:
{
"view": {
"lastView": "slideView",
"showComments": true,
"gridSpacing": { "cx": 50800, "cy": 50800 }
},
"slides": [
{
"children": [{ "shape": { "textBody": { "children": ["Slide with view settings"] } } }]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
view: {
lastView: "slideView",
showComments: true,
gridSpacing: { cx: 50800, cy: 50800 },
},
slides: [
{
children: [{ shape: { textBody: { text: "Slide with view settings" } } }],
},
],
});
视图选项
| 选项 | 类型 | 说明 |
|---|---|---|
lastView | string | 上次活动视图("slideView"、"slideMasterView"、"notesView"、"handoutView"、"outlineView"、"slideSorterView") |
showComments | boolean | 显示批注 |
gridSpacing | object | 网格间距 { cx, cy },单位为 EMU |
zoomScaleNumerator | number | 缩放比例分子 |
zoomScaleDenominator | number | 缩放比例分母 |
normalView | object | 普通视图设置 |
slideView | object | 幻灯片视图设置 |
普通视图选项
| 选项 | 类型 | 说明 |
|---|---|---|
showOutlineIcons | boolean | 显示大纲图标 |
snapVertSplitter | boolean | 对齐垂直分隔条 |
vertBarState | string | "restored"、"maximized" 或 "minimized" |
horzBarState | string | "restored"、"maximized" 或 "minimized" |
preferSingleView | boolean | 首选单视图 |
幻灯片视图选项
| 选项 | 类型 | 说明 |
|---|---|---|
snapToGrid | boolean | 对齐网格 |
snapToObjects | boolean | 对齐对象 |
showGuides | boolean | 显示参考线 |
varScale | boolean | 可变缩放 |
放映、Web 和打印属性
配置幻灯片放映、Web 发布和打印设置:
{
"show": {
"type": "present",
"showNarration": true,
"useTimings": true
},
"web": {
"showAnimation": true,
"resizeGraphics": true
},
"print": {
"printWhat": "handouts4",
"colorMode": "color"
},
"slides": [
{
"children": [{ "shape": { "textBody": { "children": ["Full presentation properties"] } } }]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
show: {
type: "present",
showNarration: true,
useTimings: true,
},
web: {
showAnimation: true,
resizeGraphics: true,
},
print: {
printWhat: "handouts4",
colorMode: "color",
},
slides: [
{
children: [{ shape: { textBody: { text: "Full presentation properties" } } }],
},
],
});
放映选项
| 选项 | 类型 | 说明 |
|---|---|---|
type | string | "present"、"kiosk" 或 "browse" |
loop | boolean | 循环放映 |
showScrollbar | boolean | 浏览模式下显示滚动条 |
slideRange | object | 幻灯片范围 { start, end }(从 1 开始) |
restart | number | 展台模式自动重启超时(毫秒) |
showNarration | boolean | 放映时播放旁白 |
showAnimation | boolean | 放映时播放动画 |
useTimings | boolean | 使用录制的排练时间 |
penColor | string | 激光笔颜色(十六进制) |
Web 选项
| 选项 | 类型 | 说明 |
|---|---|---|
showAnimation | boolean | 在 Web 中显示动画 |
resizeGraphics | boolean | 调整图形大小 |
allowPng | boolean | 允许 PNG 图片 |
relyOnVml | boolean | 依赖 VML |
organizeInFolders | boolean | 按文件夹组织 |
useLongFilenames | boolean | 使用长文件名 |
imageSize | string | 图片大小 |
encoding | string | 字符编码 |
color | string | 颜色模式 |
打印选项
| 选项 | 类型 | 说明 |
|---|---|---|
printWhat | string | 打印内容("slides"、"handouts1"、"handouts2"、"handouts3"、"handouts4"、"handouts6"、"handouts9"、"notes"、"outline") |
colorMode | string | "color"、"gray" 或 "blackWhite" |
hiddenSlides | boolean | 打印隐藏的幻灯片 |
scaleToFitPaper | boolean | 缩放以适应纸张 |
frameSlides | boolean | 给幻灯片加边框 |
HTML 发布
配置 HTML 发布属性,用于 Web 输出:
{
"htmlPublish": {
"showSpeakerNotes": true,
"title": "Published Slides",
"rId": "rId1"
},
"slides": [
{
"children": [{ "shape": { "textBody": { "children": ["HTML publish demo"] } } }]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
htmlPublish: {
showSpeakerNotes: true,
title: "Published Slides",
rId: "rId1",
},
slides: [
{
children: [{ shape: { textBody: { text: "HTML publish demo" } } }],
},
],
});
HTML 发布选项
| 选项 | 类型 | 说明 |
|---|---|---|
showSpeakerNotes | boolean | 包含演讲者备注 |
title | string | 发布的演示文稿标题 |
rId | string | 关系 ID |
相册
创建相册演示文稿,支持布局和边框选项:
{
"photoAlbum": {
"showCaptions": true,
"layout": "2pic",
"frame": "frameStyle1"
},
"slides": [
{
"children": [{ "shape": { "textBody": { "children": ["Photo Album"] } } }]
}
]
}
import { generatePresentation } from "@office-open/pptx";
generatePresentation({
photoAlbum: {
showCaptions: true,
layout: "2pic",
frame: "frameStyle1",
},
slides: [
{
children: [{ shape: { textBody: { text: "Photo Album" } } }],
},
],
});
相册选项
| 选项 | 类型 | 说明 |
|---|---|---|
blackWhite | boolean | 黑白模式 |
showCaptions | boolean | 在图片下方显示标题 |
layout | string | "fitToSlide"、"1pic"、"2pic"、"4pic"、"1picTitle"、"2picTitle"、"4picTitle" |
frame | string | "frameStyle1" 到 "frameStyle7",或 "none" |