pptxtojson 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README_zh.md ADDED
@@ -0,0 +1,353 @@
1
+ # 🎨 pptxtojson
2
+
3
+ [![npm-version](https://img.shields.io/npm/v/pptxtojson)](https://www.npmjs.com/package/pptxtojson)
4
+ [![npm download](https://img.shields.io/npm/dm/pptxtojson)](https://www.npmjs.com/package/pptxtojson)
5
+ [![GitHub issues](https://img.shields.io/github/issues-closed/pipipi-pikachu/pptxtojson)](https://github.com/pipipi-pikachu/pptxtojson/issues)
6
+ [![license](https://img.shields.io/github/license/pipipi-pikachu/pptxtojson)](https://www.github.com/pipipi-pikachu/pptxtojson/blob/master/LICENSE)
7
+ [![GitHub stars](https://img.shields.io/github/stars/pipipi-pikachu/pptxtojson)](https://www.github.com/pipipi-pikachu/pptxtojson/stargazers)
8
+ [![GitHub forks](https://img.shields.io/github/forks/pipipi-pikachu/pptxtojson)](https://www.github.com/pipipi-pikachu/pptxtojson/network/members)
9
+
10
+ 简体中文 | [English](README.md)
11
+
12
+ **pptxtojson 是一个浏览器优先的 PPTX 解析库,可以将 `.pptx` 文件转换为干净、可读、结构化的 JSON。**
13
+
14
+ 在线体验:https://pipipi-pikachu.github.io/pptxtojson/
15
+
16
+ > 国内镜像(定期同步):[Gitee](https://gitee.com/pptist/pptxtojson)、[GitCode](https://gitcode.com/pipipi-pikachu/pptxtojson)
17
+
18
+ # ✨ 核心能力
19
+
20
+ - **浏览器端解析**:直接读取 `.pptx` 文件,适合在前端处理用户本地文件,无需上传服务端转换。
21
+ - **可读 JSON 输出**:按页面、元素、资源、主题等维度组织结果,而不是把 Office XML 原样翻译成低层结构。
22
+ - **面向二次处理**:相比单纯转成 HTML 页面,更关注数据可读性和可编程性,方便接入后续业务流程。
23
+
24
+ # 🚀 适用场景
25
+
26
+ - **Web 编辑器导入**:将 PPTX 页面和元素转换为可编辑的数据模型(如 [PPTist](https://github.com/pipipi-pikachu/PPTist))。
27
+ - **内容提取**:抽取文本、备注、媒体资源,用于搜索、归档、审核或数据分析。
28
+ - **AI 文档理解**:把幻灯片内容整理为结构化输入,用于总结、问答、知识库入库等流程。
29
+ - **自定义渲染**:基于 JSON 结果生成自己的预览、缩略图、编辑画布或转换流程。
30
+
31
+ # 🔨安装
32
+ ```
33
+ npm install pptxtojson
34
+ ```
35
+
36
+ # 💿用法
37
+ ```javascript
38
+ parse(file, options = {})
39
+ ```
40
+
41
+ ### 浏览器示例
42
+ ```html
43
+ <input type="file" accept="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
44
+ ```
45
+
46
+ ```javascript
47
+ import { parse } from 'pptxtojson'
48
+
49
+ document.querySelector('input').addEventListener('change', evt => {
50
+ const file = evt.target.files[0]
51
+
52
+ const reader = new FileReader()
53
+ reader.onload = async e => {
54
+ const json = await parse(e.target.result, {
55
+ imageMode: 'base64',
56
+ videoMode: 'none',
57
+ audioMode: 'none',
58
+ })
59
+ console.log(json)
60
+ }
61
+ reader.readAsArrayBuffer(file)
62
+ })
63
+ ```
64
+
65
+ ### Node.js 示例(实验性,1.5.0以上版本)
66
+ ```javascript
67
+ const pptxtojson = require('pptxtojson/dist/index.cjs')
68
+ const fs = require('fs')
69
+
70
+ async function func() {
71
+ const buffer = fs.readFileSync('test.pptx')
72
+
73
+ const json = await pptxtojson.parse(buffer.buffer, {
74
+ imageMode: 'base64',
75
+ videoMode: 'none',
76
+ audioMode: 'none',
77
+ })
78
+ console.log(json)
79
+ }
80
+
81
+ func()
82
+ ```
83
+
84
+ ### 输出示例
85
+ ```javascript
86
+ {
87
+ "slides": [
88
+ {
89
+ "fill": {
90
+ "type": "color",
91
+ "value": "#FF0000"
92
+ },
93
+ "elements": [
94
+ {
95
+ "left": 0,
96
+ "top": 0,
97
+ "width": 72,
98
+ "height": 72,
99
+ "borderColor": "#1F4E79",
100
+ "borderWidth": 1,
101
+ "borderType": "solid",
102
+ "borderStrokeDasharray": 0,
103
+ "fill": {
104
+ "type": "color",
105
+ "value": "#FF0000"
106
+ },
107
+ "content": "<p style=\"text-align: center;\"><span style=\"font-size: 18pt;font-family: Calibri;\">TEST</span></p>",
108
+ "isFlipV": false,
109
+ "isFlipH": false,
110
+ "rotate": 0,
111
+ "vAlign": "mid",
112
+ "name": "矩形 1",
113
+ "type": "shape",
114
+ "shapType": "rect"
115
+ },
116
+ // more...
117
+ ],
118
+ "layoutElements": [
119
+ // more...
120
+ ],
121
+ "note": "演讲者备注内容..."
122
+ },
123
+ // more...
124
+ ],
125
+ "themeColors": ['#4472C4', '#ED7D31', '#A5A5A5', '#FFC000', '#5B9BD5', '#70AD47'],
126
+ "size": {
127
+ "width": 960,
128
+ "height": 540
129
+ }
130
+ }
131
+ ```
132
+
133
+ # 🎲 Options 配置说明
134
+ > options 为可选参数,不传时使用默认配置。
135
+
136
+ - `imageMode`:控制图片资源的解析方式,可选值为 `base64`、`blob`、`both`、`none`,默认值为 `base64`。
137
+ - `base64` 表示仅解析 `base64`。
138
+ - `blob` 表示仅解析 `blob`。
139
+ - `both` 表示同时解析 `base64` 和 `blob`。
140
+ - `none` 表示不解析图片内容。
141
+
142
+ - `videoMode`:控制视频资源的解析方式,可选值为 `blob`、`none`,默认值为 `none`。
143
+ - `blob` 表示解析视频 `blob`。
144
+ - `none` 表示不解析视频内容。
145
+
146
+ - `audioMode`:控制音频资源的解析方式,可选值为 `blob`、`none`,默认值为 `none`。
147
+ - `blob` 表示解析音频 `blob`。
148
+ - `none` 表示不解析音频内容。
149
+
150
+ # 🎯 注意事项
151
+
152
+ 目前解析结果与源文件在排版和样式上的综合还原度约为 80%+。对于普通用户手动从头创建和编辑的 PPTX,常见页面结构与基础样式甚至可以达到 95%+ 的还原度。
153
+
154
+ 但是如果文件来自网上下载的复杂模板,或由 PPT 水平较高的用户大量使用“高级技巧”制作(如复杂母版、深层组合、特殊图形效果、复杂渐变、非标准形状、复杂 SmartArt 等),解析难度会明显上升,还原度也会相应降低。此类文件更适合作为复杂样本单独评估。
155
+
156
+ ### 长度值单位
157
+ 输出的 JSON 中,所有数值长度值单位都为 `pt`(point)。
158
+
159
+ ### 旧版本说明
160
+ - 在0.x版本中,所有输出的长度值单位都是px(像素)
161
+ - 在1.x及以下版本:
162
+ - 图片元素使用 `src` 字段返回 base64 数据;
163
+ - 图片填充仅返回 `picBase64`;
164
+ - 视频元素可能返回 `blob` 或 `src`;
165
+ - 音频元素仅返回 `blob`;
166
+ - 公式图片仅返回 `picBase64`;
167
+
168
+ # 📕 解析属性
169
+
170
+ - 幻灯片主题色 `themeColors`
171
+
172
+ - 内嵌字体清单 `usedFonts`
173
+
174
+ - 幻灯片尺寸 `size`
175
+ - 宽度 `width`
176
+ - 高度 `height`
177
+
178
+ - 幻灯片页面 `slides`
179
+
180
+ - 页面备注 `note`
181
+
182
+ - 页面背景填充(颜色、图片、渐变、图案) `fill`
183
+ - 纯色填充 `type='color'`
184
+ - 图片填充 `type='image'`
185
+ - 渐变填充 `type='gradient'`
186
+ - 图案填充 `type='pattern'`
187
+
188
+ - 页面切换动画 `transition`
189
+ - 类型 `type`
190
+ - 持续时间 `duration`
191
+ - 方向 `direction`
192
+
193
+ - 页面内元素 `elements` / 母版元素 `layoutElements`
194
+ - 文字
195
+ - 类型 `type='text'`
196
+ - 水平坐标 `left`
197
+ - 垂直坐标 `top`
198
+ - 宽度 `width`
199
+ - 高度 `height`
200
+ - 边框颜色 `borderColor`
201
+ - 边框宽度 `borderWidth`
202
+ - 边框类型(实线、点线、虚线) `borderType`
203
+ - 非实线边框样式 `borderStrokeDasharray`
204
+ - 阴影 `shadow`
205
+ - 填充(颜色、图片、渐变、图案) `fill`
206
+ - 内容文字(HTML富文本) `content`:
207
+ - 行内样式/结构:字体、字号、颜色、渐变、下划线、删除线、斜体、加粗、字间距、阴影、角标、超链接
208
+ - 块级样式/结构:水平对齐、行距、段间距、缩进、首行缩进、项目符号、编号列表
209
+ - 垂直翻转 `isFlipV`
210
+ - 水平翻转 `isFlipH`
211
+ - 旋转角度 `rotate`
212
+ - 垂直对齐方向 `vAlign`
213
+ - 是否为竖向文本 `isVertical`
214
+ - 元素名 `name`
215
+ - 自动调整大小 `autoFit`
216
+ - 类型 `type`
217
+ - `shape`:文本框高度会根据文本内容自动调整
218
+ - `text`:文本框大小固定,字号会自动缩放以适应文本框(注:autoFit不存在时,也会固定文本框大小,但字号不会缩放)
219
+ - 字体缩放比例(type='text'专有,默认为1) `fontScale`
220
+ - 文本内边距(4边) `textInset`
221
+ - 超链接 `link`
222
+
223
+ - 图片
224
+ - 类型 `type='image'`
225
+ - 水平坐标 `left`
226
+ - 垂直坐标 `top`
227
+ - 宽度 `width`
228
+ - 高度 `height`
229
+ - 边框颜色 `borderColor`
230
+ - 边框宽度 `borderWidth`
231
+ - 边框类型(实线、点线、虚线) `borderType`
232
+ - 非实线边框样式 `borderStrokeDasharray`
233
+ - 裁剪形状 `geom`
234
+ - 裁剪范围 `rect`
235
+ - 资源引用路径 `ref`
236
+ - 图片base64 `base64`
237
+ - 图片blob `blob`
238
+ - 旋转角度 `rotate`
239
+ - 滤镜 `filters`
240
+ - 超链接 `link`
241
+
242
+ - 形状
243
+ - 类型 `type='shape'`
244
+ - 水平坐标 `left`
245
+ - 垂直坐标 `top`
246
+ - 宽度 `width`
247
+ - 高度 `height`
248
+ - 边框颜色 `borderColor`
249
+ - 边框宽度 `borderWidth`
250
+ - 边框类型(实线、点线、虚线) `borderType`
251
+ - 非实线边框样式 `borderStrokeDasharray`
252
+ - 阴影 `shadow`
253
+ - 填充(颜色、图片、渐变、图案) `fill`
254
+ - 仅描边(无填充) `strokeOnly`
255
+ - 内容文字(HTML富文本,与文字元素一致) `content`
256
+ - 垂直翻转 `isFlipV`
257
+ - 水平翻转 `isFlipH`
258
+ - 旋转角度 `rotate`
259
+ - 形状类型 `shapType`
260
+ - 垂直对齐方向 `vAlign`
261
+ - 形状路径 `path`
262
+ - 形状路径 viewBox `pathViewBox`
263
+ - 形状调整参数 `keypoints`
264
+ - 元素名 `name`
265
+ - 自动调整大小 `autoFit`
266
+ - 文本内边距(4边) `textInset`
267
+ - 超链接 `link`
268
+
269
+ - 表格
270
+ - 类型 `type='table'`
271
+ - 水平坐标 `left`
272
+ - 垂直坐标 `top`
273
+ - 宽度 `width`
274
+ - 高度 `height`
275
+ - 边框(4边) `borders`
276
+ - 单元格样式与数据 `data`
277
+ - 行高 `rowHeights`
278
+ - 列宽 `colWidths`
279
+
280
+ - 图表
281
+ - 类型 `type='chart'`
282
+ - 水平坐标 `left`
283
+ - 垂直坐标 `top`
284
+ - 宽度 `width`
285
+ - 高度 `height`
286
+ - 图表数据 `data`
287
+ - 图表主题色 `colors`
288
+ - 图表类型 `chartType`
289
+ - 柱状图方向 `barDir`
290
+ - 是否带数据标记 `marker`
291
+ - 环形图尺寸 `holeSize`
292
+ - 分组模式 `grouping`
293
+ - 图表样式 `style`
294
+
295
+ - 视频
296
+ - 类型 `type='video'`
297
+ - 水平坐标 `left`
298
+ - 垂直坐标 `top`
299
+ - 宽度 `width`
300
+ - 高度 `height`
301
+ - 资源引用路径 `ref`
302
+ - 视频blob `blob`
303
+
304
+ - 音频
305
+ - 类型 `type='audio'`
306
+ - 水平坐标 `left`
307
+ - 垂直坐标 `top`
308
+ - 宽度 `width`
309
+ - 高度 `height`
310
+ - 资源引用路径 `ref`
311
+ - 音频blob `blob`
312
+
313
+ - 公式
314
+ - 类型 `type='math'`
315
+ - 水平坐标 `left`
316
+ - 垂直坐标 `top`
317
+ - 宽度 `width`
318
+ - 高度 `height`
319
+ - 公式图片引用路径 `picRef`
320
+ - 公式图片base64 `picBase64`
321
+ - 公式图片blob `picBlob`
322
+ - LaTeX表达式(仅支持常见结构) `latex`
323
+ - 文本(文本和公式混排时存在) `text`
324
+
325
+ - Smart图
326
+ - 类型 `type='diagram'`
327
+ - 水平坐标 `left`
328
+ - 垂直坐标 `top`
329
+ - 宽度 `width`
330
+ - 高度 `height`
331
+ - 子元素集合 `elements`
332
+ - 文本列表(Smart图中的文字内容清单) `textList`
333
+
334
+ - 多元素组合
335
+ - 类型 `type='group'`
336
+ - 水平坐标 `left`
337
+ - 垂直坐标 `top`
338
+ - 宽度 `width`
339
+ - 高度 `height`
340
+ - 子元素集合 `elements`
341
+
342
+ ### 更详细类型请参考 👇
343
+ [https://github.com/pipipi-pikachu/pptxtojson/blob/master/dist/index.d.ts](https://github.com/pipipi-pikachu/pptxtojson/blob/master/dist/index.d.ts)
344
+
345
+ # 🙏 感谢
346
+ 本仓库大量参考了 [PPTX2HTML](https://github.com/g21589/PPTX2HTML) 和 [PPTXjs](https://github.com/meshesha/PPTXjs) 的实现。
347
+
348
+ 与它们不同的是:pptxtojson 的目标不是将 PPT 文件转换为 HTML 页面,而是输出干净、易读、便于二次处理的 JSON 数据,并在原有基础上进行了大量优化补充,提升了提取信息的完整度和准确度。
349
+
350
+ 欢迎通过 Issue / PR 反馈更多 PPTX 样本、解析场景和改进建议。
351
+
352
+ # 📄 开源协议
353
+ MIT License | Copyright © 2020-PRESENT [pipipi-pikachu](https://github.com/pipipi-pikachu)