pptxtojson 0.1.8 → 1.0.1
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.md +38 -15
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/index.html +1 -4
- package/package.json +1 -1
- package/src/color.js +9 -0
- package/src/constants.js +3 -0
- package/src/fill.js +21 -22
- package/src/fontStyle.js +4 -4
- package/src/position.js +8 -6
- package/src/pptxtojson.js +143 -79
- package/src/shadow.js +7 -7
- package/src/table.js +126 -0
- package/src/text.js +2 -2
- package/src/utils.js +2 -5
package/README.md
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
# 🎨 pptxtojson
|
|
2
|
-
|
|
2
|
+
一个运行在浏览器中,可以将 .pptx 文件转为可读的 JSON 数据的 JavaScript 库。
|
|
3
|
+
|
|
4
|
+
> 与其他的pptx文件解析工具的最大区别在于:
|
|
5
|
+
> 1. 直接运行在浏览器端;
|
|
6
|
+
> 2. 解析结果是**可读**的 JSON 数据,而不仅仅是把 XML 文件内容原样翻译成 JSON。
|
|
3
7
|
|
|
4
8
|
在线DEMO:https://pipipi-pikachu.github.io/pptxtojson/
|
|
5
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(像素)
|
|
6
19
|
|
|
7
20
|
# 🔨安装
|
|
8
21
|
```
|
|
@@ -17,17 +30,12 @@ npm install pptxtojson
|
|
|
17
30
|
```js
|
|
18
31
|
import { parse } from 'pptxtojson'
|
|
19
32
|
|
|
20
|
-
const options = {
|
|
21
|
-
slideFactor: 75 / 914400, // 幻灯片尺寸转换因子,默认 96 / 914400
|
|
22
|
-
fontsizeFactor: 100 / 96, // 字号转换因子,默认 100 / 75
|
|
23
|
-
}
|
|
24
|
-
|
|
25
33
|
document.querySelector('input').addEventListener('change', evt => {
|
|
26
34
|
const file = evt.target.files[0]
|
|
27
35
|
|
|
28
36
|
const reader = new FileReader()
|
|
29
37
|
reader.onload = async e => {
|
|
30
|
-
const json = await parse(e.target.result
|
|
38
|
+
const json = await parse(e.target.result)
|
|
31
39
|
console.log(json)
|
|
32
40
|
}
|
|
33
41
|
reader.readAsArrayBuffer(file)
|
|
@@ -43,19 +51,35 @@ document.querySelector('input').addEventListener('change', evt => {
|
|
|
43
51
|
"value": "#FF0000"
|
|
44
52
|
},
|
|
45
53
|
"elements": [
|
|
46
|
-
|
|
54
|
+
{
|
|
55
|
+
"left": 0,
|
|
56
|
+
"top": 0,
|
|
57
|
+
"width": 72,
|
|
58
|
+
"height": 72,
|
|
59
|
+
"borderColor": "#1f4e79",
|
|
60
|
+
"borderWidth": 1,
|
|
61
|
+
"borderType": "solid",
|
|
62
|
+
"borderStrokeDasharray": 0,
|
|
63
|
+
"fillColor": "#5b9bd5",
|
|
64
|
+
"content": "<p style=\"text-align: center;\"><span style=\"font-size: 18pt;font-family: Calibri;\">TEST</span></p>",
|
|
65
|
+
"isFlipV": false,
|
|
66
|
+
"isFlipH": false,
|
|
67
|
+
"rotate": 0,
|
|
68
|
+
"vAlign": "mid",
|
|
69
|
+
"name": "矩形 1",
|
|
70
|
+
"type": "shape",
|
|
71
|
+
"shapType": "rect"
|
|
72
|
+
},
|
|
73
|
+
// more...
|
|
47
74
|
],
|
|
48
75
|
},
|
|
49
76
|
"size": {
|
|
50
|
-
"width":
|
|
51
|
-
"height":
|
|
77
|
+
"width": 960,
|
|
78
|
+
"height": 540
|
|
52
79
|
}
|
|
53
80
|
}
|
|
54
81
|
```
|
|
55
82
|
|
|
56
|
-
# 📏 输出值单位
|
|
57
|
-
为了方便在web应用中使用,在默认情况下,所有输出的长度值单位都是px(像素),但这个值不一定是正确的,你可能需要根据你的设备情况适当调整 `slideFactor` 和 `fontsizeFactor` 参数来获取更准确的结果。或者将这个两个参数全部设置为1,这样输出的将会是原始数据,你可以在此基础上将原数据根据具体情况进行转换。
|
|
58
|
-
|
|
59
83
|
# 📕 功能支持
|
|
60
84
|
|
|
61
85
|
### 幻灯片尺寸
|
|
@@ -135,8 +159,7 @@ document.querySelector('input').addEventListener('change', evt => {
|
|
|
135
159
|
| top | number | 垂直坐标
|
|
136
160
|
| width | number | 宽度
|
|
137
161
|
| height | number | 高度
|
|
138
|
-
| data | TableCell[][] | 表格数据
|
|
139
|
-
| themeColor | string | 主题颜色
|
|
162
|
+
| data | TableCell[][] | 表格数据
|
|
140
163
|
|
|
141
164
|
#### 图表
|
|
142
165
|
| prop | type | 描述
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,9 @@ export interface TableCell {
|
|
|
66
66
|
colSpan?: number
|
|
67
67
|
vMerge?: boolean
|
|
68
68
|
hMerge?: boolean
|
|
69
|
+
fillColor?: string
|
|
70
|
+
fontColor?: string
|
|
71
|
+
fontBold?: boolean
|
|
69
72
|
}
|
|
70
73
|
export interface Table {
|
|
71
74
|
type: 'table'
|
|
@@ -74,7 +77,6 @@ export interface Table {
|
|
|
74
77
|
width: number
|
|
75
78
|
height: number
|
|
76
79
|
data: TableCell[][]
|
|
77
|
-
themeColor: string
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
export type ChartType = 'lineChart' |
|