pptx-glimpse 0.1.1 → 0.1.3

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 CHANGED
@@ -1,11 +1,27 @@
1
1
  # pptx-glimpse
2
2
 
3
- A TypeScript library for converting PPTX slides to SVG / PNG.
3
+ [![npm](https://img.shields.io/npm/v/pptx-glimpse)](https://www.npmjs.com/package/pptx-glimpse)
4
+
5
+ A Node.js library to render PPTX as SVG / PNG.
6
+
7
+ [Demo](https://pptx-glimpse.vercel.app/) | [npm](https://www.npmjs.com/package/pptx-glimpse)
8
+
9
+ ## Motivation
10
+
11
+ pptx-glimpse is designed for two primary use cases:
12
+
13
+ - **Frontend PPTX preview** — Render slide thumbnails without depending on
14
+ Microsoft Office or LibreOffice. The SVG output can be embedded directly
15
+ in web pages.
16
+ - **AI image recognition** — Convert slides to PNG so that vision-capable LLMs
17
+ can understand slide content and layout.
18
+
19
+ The library focuses on accurately reproducing text, shapes, and spatial layout
20
+ rather than pixel-perfect rendering of every PowerPoint feature.
4
21
 
5
22
  ## Requirements
6
23
 
7
- - **Node.js >= 20** (does not work in browser environments)
8
- - Requires a platform supported by [sharp](https://sharp.pixelplumbing.com/), which is used for PNG conversion
24
+ - **Node.js >= 20**
9
25
 
10
26
  ## Installation
11
27
 
@@ -16,7 +32,7 @@ npm install pptx-glimpse
16
32
  ## Usage
17
33
 
18
34
  ```typescript
19
- import { readFileSync } from "fs";
35
+ import { readFileSync, writeFileSync } from "fs";
20
36
  import { convertPptxToSvg, convertPptxToPng } from "pptx-glimpse";
21
37
 
22
38
  const pptx = readFileSync("presentation.pptx");
@@ -28,6 +44,67 @@ const svgResults = await convertPptxToSvg(pptx);
28
44
  // Convert to PNG
29
45
  const pngResults = await convertPptxToPng(pptx);
30
46
  // [{ slideNumber: 1, png: Buffer, width: 960, height: 540 }, ...]
47
+
48
+ writeFileSync("slide1.png", pngResults[0].png);
49
+ ```
50
+
51
+ ### Options
52
+
53
+ Both `convertPptxToSvg` and `convertPptxToPng` accept an optional `ConvertOptions` object.
54
+
55
+ ```typescript
56
+ const results = await convertPptxToPng(pptx, {
57
+ slides: [1, 3], // Convert only slides 1 and 3
58
+ width: 1920, // Output width in pixels (default: 960)
59
+ logLevel: "warn", // Warning log level: "off" | "warn" | "error"
60
+ fontDirs: ["/custom/fonts"], // Additional font directories to search
61
+ fontMapping: {
62
+ "Custom Corp Font": "Noto Sans", // Custom font name mapping
63
+ },
64
+ });
65
+ ```
66
+
67
+ ## Fonts
68
+
69
+ ### Automatic Font Loading
70
+
71
+ pptx-glimpse automatically scans system font directories and loads fonts using [opentype.js](https://opentype.js.org/). Text in SVG output is converted to `<path>` elements, ensuring consistent rendering regardless of the environment.
72
+
73
+ Default system font directories:
74
+
75
+ | OS | Directories |
76
+ | ------- | ------------------------------------------------------------ |
77
+ | Linux | `/usr/share/fonts`, `/usr/local/share/fonts` |
78
+ | macOS | `/System/Library/Fonts`, `/Library/Fonts`, `~/Library/Fonts` |
79
+ | Windows | `C:\Windows\Fonts` |
80
+
81
+ Use the `fontDirs` option to add custom font directories.
82
+
83
+ ### Font Mapping
84
+
85
+ PPTX files often reference proprietary fonts (e.g., Calibri, Meiryo). pptx-glimpse maps these to open-source alternatives available on Google Fonts.
86
+
87
+ Default mapping:
88
+
89
+ | PPTX Font | Mapped to |
90
+ | ----------------------------------- | ------------- |
91
+ | Calibri | Carlito |
92
+ | Arial | Arimo |
93
+ | Times New Roman | Tinos |
94
+ | Courier New | Cousine |
95
+ | Cambria | Caladea |
96
+ | Meiryo / Yu Gothic / MS Gothic etc. | Noto Sans JP |
97
+ | MS Mincho / Yu Mincho etc. | Noto Serif JP |
98
+
99
+ You can customize the mapping via the `fontMapping` option:
100
+
101
+ ```typescript
102
+ const results = await convertPptxToSvg(pptx, {
103
+ fontMapping: {
104
+ "Custom Corp Font": "Noto Sans", // Add a new mapping
105
+ Arial: "Inter", // Override the default
106
+ },
107
+ });
31
108
  ```
32
109
 
33
110
  ## Feature Support
@@ -38,104 +115,115 @@ Supports conversion of static visual content in PowerPoint. Dynamic elements suc
38
115
 
39
116
  #### Shapes
40
117
 
41
- | Feature | Details |
42
- | -------------- | ------------------------------------------------------------------------------------------------ |
43
- | Preset shapes | 113 types (rectangles, ellipses, arrows, flowcharts, callouts, stars, math symbols, etc.) |
44
- | Custom shapes | Arbitrary shape drawing using custom paths (moveTo, lnTo, cubicBezTo, close) |
45
- | Connectors | Line connector drawing, line style / color / width settings |
46
- | Groups | Shape grouping, nested groups |
47
- | Transforms | Position, size, rotation, flip (flipH/flipV), adjustment values |
118
+ | Feature | Details |
119
+ | ------------- | ------------------------------------------------------------------------------------------------------------------------------ |
120
+ | Preset shapes | 136 types (rectangles, ellipses, arrows, flowcharts, callouts, stars, math symbols, etc.) |
121
+ | Custom shapes | Arbitrary shape drawing using custom paths (moveTo, lnTo, cubicBezTo, quadBezTo, arcTo, close), adjust values / guide formulas |
122
+ | Connectors | Straight / bent / curved connectors, arrow endpoints (headEnd/tailEnd), line style / color / width |
123
+ | Groups | Shape grouping, nested groups, group rotation / flip |
124
+ | Transforms | Position, size, rotation, flip (flipH/flipV), adjustment values |
48
125
 
49
126
  #### Text
50
127
 
51
- | Feature | Details |
52
- | -------------- | -------------------------------------------------------------------------------------------------------------------- |
53
- | Character formatting | Font size, font family (East Asian font support), bold, italic, underline, strikethrough, font color, superscript / subscript |
128
+ | Feature | Details |
129
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
130
+ | Character formatting | Font size, font family (East Asian font support), bold, italic, underline, strikethrough, font color, superscript / subscript, hyperlinks |
54
131
  | Paragraph formatting | Horizontal alignment (left/center/right/justify), vertical anchor (top/center/bottom), line spacing, before/after paragraph spacing, indent |
55
- | Bullet points | Character bullets (buChar), auto-numbering (buAutoNum, 9 types), bullet font / color / size |
56
- | Text boxes | Word wrap (square/none), auto-fit (noAutofit/normAutofit/spAutofit), font scaling, margins |
57
- | Word wrapping | Word wrapping for English, Japanese, and CJK text, wrapping with mixed font sizes |
132
+ | Bullet points | Character bullets (buChar), auto-numbering (buAutoNum, 9 types), bullet font / color / size |
133
+ | Text boxes | Word wrap (square/none), auto-fit (noAutofit/normAutofit/spAutofit), font scaling, margins |
134
+ | Word wrapping | Word wrapping for English, Japanese, and CJK text, wrapping with mixed font sizes |
135
+ | Style inheritance | Full text style inheritance chain (run → paragraph default → body lstStyle → layout → master → txStyles → defaultTextStyle → theme fonts) |
136
+ | Tab stops / fields | Tab stop positions, field codes (slide number, date, etc.) |
58
137
 
59
138
  #### Fill
60
139
 
61
- | Feature | Details |
62
- | -------------- | ---------------------------------------------------- |
63
- | Solid color | RGB color specification, transparency |
64
- | Gradient | Linear gradient, multiple gradient stops, angle |
65
- | Image fill | PNG/JPEG/GIF, stretch mode |
66
- | No fill | noFill specification |
140
+ | Feature | Details |
141
+ | ------------ | ---------------------------------------------------------------- |
142
+ | Solid color | RGB color specification, transparency |
143
+ | Gradient | Linear gradient, radial gradient, multiple gradient stops, angle |
144
+ | Image fill | PNG/JPEG/GIF, stretch mode, cropping (srcRect) |
145
+ | Pattern fill | Hatching patterns (horizontal, vertical, diagonal, cross, etc.) |
146
+ | Group fill | Inherit fill from parent group |
147
+ | No fill | noFill specification |
67
148
 
68
149
  #### Lines & Borders
69
150
 
70
- | Feature | Details |
71
- | -------------- | ------------------------------------------------------------- |
72
- | Line style | Line width, solid color, transparency |
73
- | Dash style | solid, dash, dot, dashDot, lgDash, lgDashDot, sysDash, sysDot |
151
+ | Feature | Details |
152
+ | ---------- | ----------------------------------------------------------------- |
153
+ | Line style | Line width, solid color, transparency, lineCap, lineJoin |
154
+ | Dash style | solid, dash, dot, dashDot, lgDash, lgDashDot, sysDash, sysDot |
155
+ | Arrows | Head / tail arrow endpoints with type, width, and length settings |
74
156
 
75
157
  #### Colors
76
158
 
77
- | Feature | Details |
78
- | -------------- | ------------------------------------------------------------------------------------ |
79
- | Color types | RGB (srgbClr), theme color (schemeClr), system color (sysClr) |
80
- | Theme colors | Color scheme (dk1, lt1, dk2, lt2, accent1-6, hlink, folHlink), color map |
81
- | Color transforms | Luminance adjustment (lumMod/lumOff), tint, shade, transparency (alpha) |
159
+ | Feature | Details |
160
+ | ---------------- | ------------------------------------------------------------------------ |
161
+ | Color types | RGB (srgbClr), theme color (schemeClr), system color (sysClr) |
162
+ | Theme colors | Color scheme (dk1, lt1, dk2, lt2, accent1-6, hlink, folHlink), color map |
163
+ | Color transforms | Luminance adjustment (lumMod/lumOff), tint, shade, transparency (alpha) |
82
164
 
83
165
  #### Effects
84
166
 
85
- | Feature | Details |
86
- | -------------- | ------------------------------------------ |
87
- | Outer shadow | Blur radius, distance, direction, color / transparency |
88
- | Inner shadow | Blur radius, distance, direction, color / transparency |
89
- | Glow | Radius, color / transparency |
90
- | Soft edge | Radius |
167
+ | Feature | Details |
168
+ | ------------ | ------------------------------------------------------ |
169
+ | Outer shadow | Blur radius, distance, direction, color / transparency |
170
+ | Inner shadow | Blur radius, distance, direction, color / transparency |
171
+ | Glow | Radius, color / transparency |
172
+ | Soft edge | Radius |
91
173
 
92
174
  #### Images
93
175
 
94
- | Feature | Details |
95
- | -------------- | ---------------------------------------------------------- |
96
- | Image elements | PNG/JPEG/GIF, position / size / rotation / flip, effects |
97
- | Image fill | Image fill for shapes and backgrounds |
176
+ | Feature | Details |
177
+ | -------------- | ---------------------------------------------------------------------------- |
178
+ | Image elements | PNG/JPEG/GIF, position / size / rotation / flip, cropping (srcRect), effects |
179
+ | Image fill | Image fill for shapes and backgrounds |
98
180
 
99
181
  #### Tables
100
182
 
101
- | Feature | Details |
102
- | ---------------- | --------------------------------------------------------------------------- |
103
- | Table structure | Row and column grid, cell merging (gridSpan/rowSpan), row height / column width |
104
- | Cell formatting | Text, fill (solid/gradient/image), borders (top/bottom/left/right, styles) |
183
+ | Feature | Details |
184
+ | --------------- | ------------------------------------------------------------------------------- |
185
+ | Table structure | Row and column grid, cell merging (gridSpan/rowSpan), row height / column width |
186
+ | Cell formatting | Text, fill (solid/gradient/image), borders (top/bottom/left/right, styles) |
105
187
 
106
188
  #### Charts
107
189
 
108
- | Feature | Details |
109
- | ---------------- | ------------------------------------------------------------------------------------ |
110
- | Supported charts | Bar chart (vertical/horizontal), line chart, pie chart, scatter plot |
111
- | Chart elements | Title, legend (position), series (name/values/categories/color), category axis, value axis |
190
+ | Feature | Details |
191
+ | ---------------- | ------------------------------------------------------------------------------------------------------------ |
192
+ | Supported charts | Bar chart (vertical/horizontal), line chart, pie chart, scatter plot, area chart, doughnut, bubble, radar |
193
+ | Chart elements | Title, legend (position), series (name/values/categories/color), category axis, value axis |
194
+
195
+ #### SmartArt
196
+
197
+ | Feature | Details |
198
+ | ------------------- | ------------------------------------------------------------------------------ |
199
+ | Pre-rendered shapes | Renders SmartArt using PowerPoint's pre-rendered drawing shapes (drawingN.xml) |
200
+ | mc:AlternateContent | Handles AlternateContent fallback mechanism used by SmartArt |
112
201
 
113
202
  #### Background & Slide Settings
114
203
 
115
- | Feature | Details |
116
- | -------------- | --------------------------------------------------------------------------------------- |
117
- | Background | Solid, gradient, image. Fallback order: slide → layout → master |
118
- | Slide size | 16:9, 4:3, custom sizes |
119
- | Theme | Theme color scheme, theme fonts (majorFont/minorFont) |
204
+ | Feature | Details |
205
+ | ------------ | ---------------------------------------------------------------------- |
206
+ | Background | Solid, gradient, image. Fallback order: slide → layout → master |
207
+ | Slide size | 16:9, 4:3, custom sizes |
208
+ | Theme | Theme color scheme, theme fonts (majorFont/minorFont), theme font refs |
209
+ | showMasterSp | Control visibility of master shapes per slide / layout |
120
210
 
121
211
  ### Unsupported Features
122
212
 
123
- | Category | Unsupported features |
124
- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------- |
125
- | Fill | Pattern fill, radial gradient, path gradient |
126
- | Effects | Reflection, 3D rotation / extrusion, artistic effects |
127
- | Charts | Area, radar, doughnut, bubble, stock, combo, histogram, box plot, waterfall, treemap, sunburst |
128
- | Chart details | Data labels, axis titles / tick marks / grid lines, error bars, trendlines |
129
- | Text | Vertical text, individual text effects (shadow/glow), text outline, text columns |
130
- | Tables | Table style template application, diagonal borders |
131
- | Shapes | Shape operations (Union/Subtract/Intersect/Fragment) |
132
- | SmartArt | All SmartArt features |
133
- | Multimedia | Embedded video / audio |
134
- | Animations | Object animations, slide transitions |
135
- | Links | Hyperlinks |
136
- | Slide elements | Slide notes, comments, headers / footers, slide numbers / dates |
137
- | Image formats | EMF/WMF (parsed but not rendered) |
138
- | Other | Macros / VBA, sections, zoom slides |
213
+ | Category | Unsupported features |
214
+ | -------------- | ---------------------------------------------------------------------------------------------- |
215
+ | Fill | Path gradient (rect/shape type) |
216
+ | Effects | Reflection, 3D rotation / extrusion, artistic effects |
217
+ | Charts | Stock, combo, histogram, box plot, waterfall, treemap, sunburst |
218
+ | Chart details | Data labels, axis titles / tick marks / grid lines, error bars, trendlines |
219
+ | Text | Individual text effects (shadow/glow), text columns |
220
+ | Tables | Table style template application, diagonal borders |
221
+ | Shapes | Shape operations (Union/Subtract/Intersect/Fragment) |
222
+ | Multimedia | Embedded video / audio |
223
+ | Animations | Object animations, slide transitions |
224
+ | Slide elements | Slide notes, comments, headers / footers, slide numbers / dates |
225
+ | Image formats | EMF/WMF (parsed but not rendered) |
226
+ | Other | Macros / VBA, sections, zoom slides |
139
227
 
140
228
  ## Test Rendering
141
229