huijia-pptxtojson 1.0.0
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/LICENSE +21 -0
- package/README.md +275 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +63 -0
- package/src/index.d.ts +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-PRESENT pipipi-pikachu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# 🎨 pptxtojson
|
|
2
|
+
一个运行在浏览器中,可以将 .pptx 文件转为可读的 JSON 数据的 JavaScript 库。
|
|
3
|
+
|
|
4
|
+
> 与其他的pptx文件解析工具的最大区别在于:
|
|
5
|
+
> 1. 直接运行在浏览器端;
|
|
6
|
+
> 2. 解析结果是**可读**的 JSON 数据,而不仅仅是把 XML 文件内容原样翻译成难以理解的 JSON。
|
|
7
|
+
|
|
8
|
+
在线DEMO:https://pipipi-pikachu.github.io/pptxtojson/
|
|
9
|
+
|
|
10
|
+
# 🎯 注意事项
|
|
11
|
+
### ⚒️ 使用场景
|
|
12
|
+
本仓库诞生于项目 [PPTist](https://github.com/pipipi-pikachu/PPTist) ,希望为其“导入 .pptx 文件功能”提供一个参考示例。不过就目前来说,解析出来的PPT信息与源文件在样式上还是存在差异。
|
|
13
|
+
|
|
14
|
+
但如果你只是需要提取PPT文件的文本内容、媒体资源信息、结构信息等,或者对排版/样式精准度没有特别高的要求,那么 pptxtojson 可能会对你有帮助。
|
|
15
|
+
|
|
16
|
+
### 📏 长度值单位
|
|
17
|
+
输出的JSON中,所有数值长度值单位都为`pt`(point)
|
|
18
|
+
> 注意:在0.x版本中,所有输出的长度值单位都是px(像素)
|
|
19
|
+
|
|
20
|
+
# 🔨安装
|
|
21
|
+
```
|
|
22
|
+
npm install pptxtojson
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# 💿用法
|
|
26
|
+
|
|
27
|
+
### 浏览器
|
|
28
|
+
```html
|
|
29
|
+
<input type="file" accept="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import { parse } from 'pptxtojson'
|
|
34
|
+
|
|
35
|
+
document.querySelector('input').addEventListener('change', evt => {
|
|
36
|
+
const file = evt.target.files[0]
|
|
37
|
+
|
|
38
|
+
const reader = new FileReader()
|
|
39
|
+
reader.onload = async e => {
|
|
40
|
+
const json = await parse(e.target.result)
|
|
41
|
+
console.log(json)
|
|
42
|
+
}
|
|
43
|
+
reader.readAsArrayBuffer(file)
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Node.js(实验性,1.5.0以上版本)
|
|
48
|
+
```javascript
|
|
49
|
+
const pptxtojson = require('pptxtojson/dist/index.cjs')
|
|
50
|
+
const fs = require('fs')
|
|
51
|
+
|
|
52
|
+
async function func() {
|
|
53
|
+
const buffer = fs.readFileSync('test.pptx')
|
|
54
|
+
|
|
55
|
+
const json = await pptxtojson.parse(buffer.buffer)
|
|
56
|
+
console.log(json)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
func()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 输出示例
|
|
63
|
+
```javascript
|
|
64
|
+
{
|
|
65
|
+
"slides": [
|
|
66
|
+
{
|
|
67
|
+
"fill": {
|
|
68
|
+
"type": "color",
|
|
69
|
+
"value": "#FF0000"
|
|
70
|
+
},
|
|
71
|
+
"elements": [
|
|
72
|
+
{
|
|
73
|
+
"left": 0,
|
|
74
|
+
"top": 0,
|
|
75
|
+
"width": 72,
|
|
76
|
+
"height": 72,
|
|
77
|
+
"borderColor": "#1F4E79",
|
|
78
|
+
"borderWidth": 1,
|
|
79
|
+
"borderType": "solid",
|
|
80
|
+
"borderStrokeDasharray": 0,
|
|
81
|
+
"fill": {
|
|
82
|
+
"type": "color",
|
|
83
|
+
"value": "#FF0000"
|
|
84
|
+
},
|
|
85
|
+
"content": "<p style=\"text-align: center;\"><span style=\"font-size: 18pt;font-family: Calibri;\">TEST</span></p>",
|
|
86
|
+
"isFlipV": false,
|
|
87
|
+
"isFlipH": false,
|
|
88
|
+
"rotate": 0,
|
|
89
|
+
"vAlign": "mid",
|
|
90
|
+
"name": "矩形 1",
|
|
91
|
+
"type": "shape",
|
|
92
|
+
"shapType": "rect"
|
|
93
|
+
},
|
|
94
|
+
// more...
|
|
95
|
+
],
|
|
96
|
+
"layoutElements": [
|
|
97
|
+
// more...
|
|
98
|
+
],
|
|
99
|
+
"note": "演讲者备注内容..."
|
|
100
|
+
},
|
|
101
|
+
// more...
|
|
102
|
+
],
|
|
103
|
+
"themeColors": ['#4472C4', '#ED7D31', '#A5A5A5', '#FFC000', '#5B9BD5', '#70AD47'],
|
|
104
|
+
"size": {
|
|
105
|
+
"width": 960,
|
|
106
|
+
"height": 540
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
# 📕 完整功能支持
|
|
112
|
+
|
|
113
|
+
- 幻灯片主题色 `themeColors`
|
|
114
|
+
|
|
115
|
+
- 幻灯片尺寸 `size`
|
|
116
|
+
- 宽度 `width`
|
|
117
|
+
- 高度 `height`
|
|
118
|
+
|
|
119
|
+
- 幻灯片页面 `slides`
|
|
120
|
+
|
|
121
|
+
- 页面备注 `note`
|
|
122
|
+
|
|
123
|
+
- 页面背景填充(颜色、图片、渐变、图案) `fill`
|
|
124
|
+
- 纯色填充 `type='color'`
|
|
125
|
+
- 图片填充 `type='image'`
|
|
126
|
+
- 渐变填充 `type='gradient'`
|
|
127
|
+
- 图案填充 `type='pattern'`
|
|
128
|
+
|
|
129
|
+
- 页面切换动画 `transition`
|
|
130
|
+
- 类型 `type`
|
|
131
|
+
- 持续时间 `duration`
|
|
132
|
+
- 方向 `direction`
|
|
133
|
+
|
|
134
|
+
- 页面内元素 `elements` / 母版元素 `layoutElements`
|
|
135
|
+
- 文字
|
|
136
|
+
- 类型 `type='text'`
|
|
137
|
+
- 水平坐标 `left`
|
|
138
|
+
- 垂直坐标 `top`
|
|
139
|
+
- 宽度 `width`
|
|
140
|
+
- 高度 `height`
|
|
141
|
+
- 边框颜色 `borderColor`
|
|
142
|
+
- 边框宽度 `borderWidth`
|
|
143
|
+
- 边框类型(实线、点线、虚线) `borderType`
|
|
144
|
+
- 非实线边框样式 `borderStrokeDasharray`
|
|
145
|
+
- 阴影 `shadow`
|
|
146
|
+
- 填充(颜色、图片、渐变、图案) `fill`
|
|
147
|
+
- 内容文字(HTML富文本:字体、字号、颜色、渐变、下划线、删除线、斜体、加粗、阴影、角标、超链接) `content`
|
|
148
|
+
- 垂直翻转 `isFlipV`
|
|
149
|
+
- 水平翻转 `isFlipH`
|
|
150
|
+
- 旋转角度 `rotate`
|
|
151
|
+
- 垂直对齐方向 `vAlign`
|
|
152
|
+
- 是否为竖向文本 `isVertical`
|
|
153
|
+
- 元素名 `name`
|
|
154
|
+
- 自动调整大小 `autoFit`
|
|
155
|
+
- 类型 `type`
|
|
156
|
+
- `shape`:文本框高度会根据文本内容自动调整
|
|
157
|
+
- `text`:文本框大小固定,字号会自动缩放以适应文本框(注:autoFit不存在时,也会固定文本框大小,但字号不会缩放)
|
|
158
|
+
- 字体缩放比例(type='text'专有,默认为1) `fontScale`
|
|
159
|
+
|
|
160
|
+
- 图片
|
|
161
|
+
- 类型 `type='image'`
|
|
162
|
+
- 水平坐标 `left`
|
|
163
|
+
- 垂直坐标 `top`
|
|
164
|
+
- 宽度 `width`
|
|
165
|
+
- 高度 `height`
|
|
166
|
+
- 边框颜色 `borderColor`
|
|
167
|
+
- 边框宽度 `borderWidth`
|
|
168
|
+
- 边框类型(实线、点线、虚线) `borderType`
|
|
169
|
+
- 非实线边框样式 `borderStrokeDasharray`
|
|
170
|
+
- 裁剪形状 `geom`
|
|
171
|
+
- 裁剪范围 `rect`
|
|
172
|
+
- 图片地址(base64) `src`
|
|
173
|
+
- 旋转角度 `rotate`
|
|
174
|
+
- 滤镜 `filters`
|
|
175
|
+
|
|
176
|
+
- 形状
|
|
177
|
+
- 类型 `type='shape'`
|
|
178
|
+
- 水平坐标 `left`
|
|
179
|
+
- 垂直坐标 `top`
|
|
180
|
+
- 宽度 `width`
|
|
181
|
+
- 高度 `height`
|
|
182
|
+
- 边框颜色 `borderColor`
|
|
183
|
+
- 边框宽度 `borderWidth`
|
|
184
|
+
- 边框类型(实线、点线、虚线) `borderType`
|
|
185
|
+
- 非实线边框样式 `borderStrokeDasharray`
|
|
186
|
+
- 阴影 `shadow`
|
|
187
|
+
- 填充(颜色、图片、渐变、图案) `fill`
|
|
188
|
+
- 内容文字(HTML富文本,与文字元素一致) `content`
|
|
189
|
+
- 垂直翻转 `isFlipV`
|
|
190
|
+
- 水平翻转 `isFlipH`
|
|
191
|
+
- 旋转角度 `rotate`
|
|
192
|
+
- 形状类型 `shapType`
|
|
193
|
+
- 垂直对齐方向 `vAlign`
|
|
194
|
+
- 形状路径 `path`
|
|
195
|
+
- 元素名 `name`
|
|
196
|
+
- 自动调整大小 `autoFit`
|
|
197
|
+
|
|
198
|
+
- 表格
|
|
199
|
+
- 类型 `type='table'`
|
|
200
|
+
- 水平坐标 `left`
|
|
201
|
+
- 垂直坐标 `top`
|
|
202
|
+
- 宽度 `width`
|
|
203
|
+
- 高度 `height`
|
|
204
|
+
- 边框(4边) `borders`
|
|
205
|
+
- 表格数据 `data`
|
|
206
|
+
- 行高 `rowHeights`
|
|
207
|
+
- 列宽 `colWidths`
|
|
208
|
+
|
|
209
|
+
- 图表
|
|
210
|
+
- 类型 `type='chart'`
|
|
211
|
+
- 水平坐标 `left`
|
|
212
|
+
- 垂直坐标 `top`
|
|
213
|
+
- 宽度 `width`
|
|
214
|
+
- 高度 `height`
|
|
215
|
+
- 图表数据 `data`
|
|
216
|
+
- 图表主题色 `colors`
|
|
217
|
+
- 图表类型 `chartType`
|
|
218
|
+
- 柱状图方向 `barDir`
|
|
219
|
+
- 是否带数据标记 `marker`
|
|
220
|
+
- 环形图尺寸 `holeSize`
|
|
221
|
+
- 分组模式 `grouping`
|
|
222
|
+
- 图表样式 `style`
|
|
223
|
+
|
|
224
|
+
- 视频
|
|
225
|
+
- 类型 `type='video'`
|
|
226
|
+
- 水平坐标 `left`
|
|
227
|
+
- 垂直坐标 `top`
|
|
228
|
+
- 宽度 `width`
|
|
229
|
+
- 高度 `height`
|
|
230
|
+
- 视频blob `blob`
|
|
231
|
+
- 视频src `src`
|
|
232
|
+
|
|
233
|
+
- 音频
|
|
234
|
+
- 类型 `type='audio'`
|
|
235
|
+
- 水平坐标 `left`
|
|
236
|
+
- 垂直坐标 `top`
|
|
237
|
+
- 宽度 `width`
|
|
238
|
+
- 高度 `height`
|
|
239
|
+
- 音频blob `blob`
|
|
240
|
+
|
|
241
|
+
- 公式
|
|
242
|
+
- 类型 `type='math'`
|
|
243
|
+
- 水平坐标 `left`
|
|
244
|
+
- 垂直坐标 `top`
|
|
245
|
+
- 宽度 `width`
|
|
246
|
+
- 高度 `height`
|
|
247
|
+
- 公式图片 `picBase64`
|
|
248
|
+
- LaTeX表达式(仅支持常见结构) `latex`
|
|
249
|
+
- 文本(文本和公式混排时存在) `text`
|
|
250
|
+
|
|
251
|
+
- Smart图
|
|
252
|
+
- 类型 `type='diagram'`
|
|
253
|
+
- 水平坐标 `left`
|
|
254
|
+
- 垂直坐标 `top`
|
|
255
|
+
- 宽度 `width`
|
|
256
|
+
- 高度 `height`
|
|
257
|
+
- 子元素集合 `elements`
|
|
258
|
+
|
|
259
|
+
- 多元素组合
|
|
260
|
+
- 类型 `type='group'`
|
|
261
|
+
- 水平坐标 `left`
|
|
262
|
+
- 垂直坐标 `top`
|
|
263
|
+
- 宽度 `width`
|
|
264
|
+
- 高度 `height`
|
|
265
|
+
- 子元素集合 `elements`
|
|
266
|
+
|
|
267
|
+
### 更多类型请参考 👇
|
|
268
|
+
[https://github.com/pipipi-pikachu/pptxtojson/blob/master/dist/index.d.ts](https://github.com/pipipi-pikachu/pptxtojson/blob/master/dist/index.d.ts)
|
|
269
|
+
|
|
270
|
+
# 🙏 感谢
|
|
271
|
+
本仓库大量参考了 [PPTX2HTML](https://github.com/g21589/PPTX2HTML) 和 [PPTXjs](https://github.com/meshesha/PPTXjs) 的实现。
|
|
272
|
+
> 与它们不同的是:PPTX2HTML 和 PPTXjs 是将PPT文件转换为能够运行的 HTML 页面,而 pptxtojson 做的是将PPT文件转换为干净的 JSON 数据,且在原有基础上进行了大量优化补充(包括代码质量和提取信息的完整度和准确度)。
|
|
273
|
+
|
|
274
|
+
# 📄 开源协议
|
|
275
|
+
MIT License | Copyright © 2020-PRESENT [pipipi-pikachu](https://github.com/pipipi-pikachu)
|