dom-to-pptx 1.0.5 → 1.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/CHANGELOG.md +22 -18
- package/Readme.md +288 -249
- package/SUPPORTED.md +50 -50
- package/dist/dom-to-pptx.bundle.js +30193 -31091
- package/dist/dom-to-pptx.cjs +1200 -1167
- package/dist/dom-to-pptx.min.js +1198 -1167
- package/dist/dom-to-pptx.mjs +1194 -1164
- package/package.json +73 -73
- package/rollup.config.js +56 -53
- package/src/image-processor.js +79 -76
- package/src/index.js +657 -657
- package/src/utils.js +479 -452
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
## [1.0.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.6] - 2025-12-06
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Standalone UMD bundle `dist/dom-to-pptx.bundle.js` which includes runtime dependencies for single-script usage.
|
|
10
|
+
- `SUPPORTED.md` listing common supported HTML elements and CSS features.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Rounded corner math: decreased false-positive circle detection and capped `rectRadius` to avoid pill-shaped elements becoming full circles.
|
|
15
|
+
- Partial border-radius clipping: elements inside `overflow:hidden` are now correctly rendered with clipping preserved.
|
|
16
|
+
- Very small elements (sub-pixel) rendering: lowered threshold to include tiny decorative elements (e.g., 2x2 dots).
|
|
17
|
+
- Backdrop blur support: simulated `backdrop-filter: blur()` using html2canvas snapshotting.
|
|
18
|
+
- CORS canvas errors: replaced fragile foreignObject rendering with safer SVG + canvas or html2canvas-based capture where appropriate.
|
|
19
|
+
|
|
20
|
+
## [1.0.3] - Previous
|
|
21
|
+
|
|
22
|
+
- Minor fixes and optimizations.
|
package/Readme.md
CHANGED
|
@@ -1,249 +1,288 @@
|
|
|
1
|
-
# dom-to-pptx
|
|
2
|
-
|
|
3
|
-
**The High-Fidelity HTML to PowerPoint Converter (v1.0.
|
|
4
|
-
|
|
5
|
-
Most HTML-to-PPTX libraries fail when faced with modern web design. They break on gradients, misalign text, ignore rounded corners, or simply take a screenshot (which isn't editable).
|
|
6
|
-
|
|
7
|
-
**dom-to-pptx** is different. It is a **Coordinate Scraper & Style Engine** that traverses your DOM, calculates the exact computed styles of every element (Flexbox/Grid positions, complex gradients, shadows), and mathematically maps them to native PowerPoint shapes and text boxes. The result is a fully editable, vector-sharp presentation that looks exactly like your web view.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
### 🎨 Advanced Visual Fidelity
|
|
12
|
-
|
|
13
|
-
- **Complex Gradients:** Includes a built-in CSS Gradient Parser that converts `linear-gradient` strings (with multiple stops, angles, and transparency) into vector SVGs for perfect rendering. This now also supports `text-fill-color` gradients, falling back to the first color for broad compatibility.
|
|
14
|
-
- **Mathematically Accurate Shadows:** Converts CSS Cartesian shadows (`x`, `y`, `blur`) into PowerPoint's Polar coordinate system (`angle`, `distance`) for 1:1 depth matching.
|
|
15
|
-
- **Anti-Halo Image Processing:** Uses off-screen HTML5 Canvas with `source-in` composite masking to render rounded images without the ugly white "halo" artifacts found in other libraries.
|
|
16
|
-
- **Soft Edges/Blurs:** Accurately translates CSS `filter: blur()` into PowerPoint's soft-edge effects, preserving visual depth.
|
|
17
|
-
|
|
18
|
-
### 📐 Smart Layout & Typography
|
|
19
|
-
|
|
20
|
-
- **Auto-Scaling Engine:** Build your slide in HTML at **1920x1080** (or any aspect ratio). The library automatically calculates the scaling factor to fit it perfectly into a standard 16:9 PowerPoint slide (10 x 5.625 inches) with auto-centering.
|
|
21
|
-
- **Rich Text Blocks:** Handles mixed-style text (e.g., **bold** spans inside a normal paragraph) while sanitizing HTML source code whitespace (newlines/tabs) to prevent jagged text alignment.
|
|
22
|
-
- **Font Stack Normalization:** Automatically maps web-only fonts (like `ui-sans-serif`, `system-ui`) to safe system fonts (`Arial`, `Calibri`) to ensure the file opens correctly on any computer.
|
|
23
|
-
- **Text Transformations:** Supports CSS `text-transform: uppercase/lowercase` and `letter-spacing` (converted to PT).
|
|
24
|
-
|
|
25
|
-
### ⚡ Technical Capabilities
|
|
26
|
-
|
|
27
|
-
- **Z-Index Handling:** Respects DOM order for correct layering of elements.
|
|
28
|
-
- **Border Radius Math:** Calculates perfect corner rounding percentages based on element dimensions.
|
|
29
|
-
- **Client-Side:** Runs entirely in the browser. No server required.
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
npm install dom-to-pptx
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
This library is intended for use in the browser (React, Vue, Svelte, Vanilla JS, etc.).
|
|
40
|
-
|
|
41
|
-
### 1. Basic Example
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
44
|
-
import { exportToPptx } from 'dom-to-pptx';
|
|
45
|
-
|
|
46
|
-
// Note: If you are using a module bundler, it is recommended to import pptxgenjs
|
|
47
|
-
// directly into your project to ensure tree-shaking and optimal bundle size.
|
|
48
|
-
// import PptxGenJS from 'pptxgenjs'; // Uncomment and use if needed for your setup
|
|
49
|
-
|
|
50
|
-
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
51
|
-
// Pass the CSS selector of the container you want to turn into a slide
|
|
52
|
-
await exportToPptx('#slide-container', {
|
|
53
|
-
fileName: 'slide-presentation.pptx',
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### 2. Multi-Slide Example
|
|
59
|
-
|
|
60
|
-
To export multiple HTML elements as separate slides, pass an array of elements or selectors:
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
import { exportToPptx } from 'dom-to-pptx'; // ESM or CJS import
|
|
64
|
-
|
|
65
|
-
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
66
|
-
const slideElements = document.querySelectorAll('.slide');
|
|
67
|
-
await exportToPptx(Array.from(slideElements), {
|
|
68
|
-
fileName: 'multi-slide-presentation.pptx',
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### 3. Browser Usage (single-file bundle or legacy setup)
|
|
74
|
-
|
|
75
|
-
You can use `dom-to-pptx` directly in the browser in two ways:
|
|
76
|
-
|
|
77
|
-
- Recommended — Single-file bundle (includes runtime deps):
|
|
78
|
-
|
|
79
|
-
```html
|
|
80
|
-
<!-- Single script that contains dom-to-pptx + pptxgenjs + html2canvas -->
|
|
81
|
-
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"></script>
|
|
82
|
-
<script>
|
|
83
|
-
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
84
|
-
// The library is available globally as `domToPptx`
|
|
85
|
-
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
86
|
-
});
|
|
87
|
-
</script>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
You can also load the bundle from a CDN (unpkg/jsdelivr):
|
|
91
|
-
|
|
92
|
-
```html
|
|
93
|
-
<script src="https://unpkg.com/dom-to-pptx@latest/dist/dom-to-pptx.bundle.js"></script>
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
- Legacy — Explicit runtime includes (smaller dom-to-pptx file, you manage deps):
|
|
97
|
-
|
|
98
|
-
```html
|
|
99
|
-
<!-- Load pptxgenjs first -->
|
|
100
|
-
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
|
|
101
|
-
<!-- html2canvas is required by the legacy dom-to-pptx build for backdrop-filter and canvas image processing -->
|
|
102
|
-
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
|
103
|
-
<!-- Then load the legacy dom-to-pptx file that expects the above libs -->
|
|
104
|
-
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.min.js"></script>
|
|
105
|
-
<script>
|
|
106
|
-
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
107
|
-
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
108
|
-
});
|
|
109
|
-
</script>
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Notes:
|
|
113
|
-
|
|
114
|
-
- The standalone `dist/dom-to-pptx.bundle.js` includes `pptxgenjs` and `html2canvas`, so you only need one script tag.
|
|
115
|
-
- If you prefer a smaller payload and already have `pptxgenjs` on the page, use the legacy `dist/dom-to-pptx.min.js` and load `pptxgenjs` first.
|
|
116
|
-
|
|
117
|
-
### 4. Recommended HTML Structure
|
|
118
|
-
|
|
119
|
-
### Recommended HTML Structure
|
|
120
|
-
|
|
121
|
-
For the best results, treat your container as a fixed-size canvas. We recommend building your slide at **1920x1080px**. The library will handle the downscaling.
|
|
122
|
-
|
|
123
|
-
```html
|
|
124
|
-
<!-- Container (16:9 Aspect Ratio) -->
|
|
125
|
-
<!-- The library will capture this background color/gradient automatically -->
|
|
126
|
-
<div
|
|
127
|
-
id="slide-container"
|
|
128
|
-
class="slide w-[1000px] h-[562px] bg-white mx-auto shadow-xl relative overflow-hidden rounded-lg flex items-center justify-center p-10"
|
|
129
|
-
>
|
|
130
|
-
<div
|
|
131
|
-
class="w-full max-w-3xl bg-white rounded-2xl shadow-xl overflow-hidden grid md:grid-cols-2 items-center
|
|
132
|
-
border-l-2 border-indigo-500"
|
|
133
|
-
>
|
|
134
|
-
<div class="p-12">
|
|
135
|
-
<h2 class="text-xl font-semibold text-indigo-500 uppercase tracking-wide mb-2">
|
|
136
|
-
Core Concept
|
|
137
|
-
</h2>
|
|
138
|
-
<h3 class="text-4xl font-bold text-slate-800 mb-6">From Bit to Qubit</h3>
|
|
139
|
-
<div class="space-y-6 text-slate-600">
|
|
140
|
-
<div class="flex items-start gap-4">
|
|
141
|
-
<div
|
|
142
|
-
class="flex-shrink-0 w-8 h-8 bg-slate-200 rounded-full flex items-center justify-center font-bold text-slate-700"
|
|
143
|
-
>
|
|
144
|
-
B
|
|
145
|
-
</div>
|
|
146
|
-
<div>
|
|
147
|
-
<h4 class="font-bold text-slate-700">Classical Bit</h4>
|
|
148
|
-
<p>
|
|
149
|
-
A fundamental unit of information that is either
|
|
150
|
-
<span class="font-semibold text-indigo-600">0</span> or
|
|
151
|
-
<span class="font-semibold text-indigo-600">1</span>.
|
|
152
|
-
</p>
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
<div class="flex items-start gap-4">
|
|
156
|
-
<div
|
|
157
|
-
class="flex-shrink-0 w-8 h-8 bg-indigo-200 rounded-full flex items-center justify-center font-bold text-indigo-700"
|
|
158
|
-
>
|
|
159
|
-
Q
|
|
160
|
-
</div>
|
|
161
|
-
<div>
|
|
162
|
-
<h4 class="font-bold text-slate-700">Quantum Bit (Qubit)</h4>
|
|
163
|
-
<p>
|
|
164
|
-
Can be <span class="font-semibold text-indigo-600">0</span>,
|
|
165
|
-
<span class="font-semibold text-indigo-600">1</span>, or a
|
|
166
|
-
<span class="font-semibold text-indigo-600">superposition</span>
|
|
167
|
-
of both states simultaneously.
|
|
168
|
-
</p>
|
|
169
|
-
</div>
|
|
170
|
-
</div>
|
|
171
|
-
</div>
|
|
172
|
-
</div>
|
|
173
|
-
<div class="h-64 md:h-full">
|
|
174
|
-
<img
|
|
175
|
-
src="https://picsum.photos/800/600?random=2"
|
|
176
|
-
alt="Stylized representation of a qubit"
|
|
177
|
-
class="w-full h-full object-cover"
|
|
178
|
-
/>
|
|
179
|
-
</div>
|
|
180
|
-
</div>
|
|
181
|
-
</div>
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## API
|
|
185
|
-
|
|
186
|
-
### `exportToPptx(elementOrSelector, options)`
|
|
187
|
-
|
|
188
|
-
| Parameter | Type | Description |
|
|
189
|
-
| :------------------ | :---------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
190
|
-
| `elementOrSelector` | `string` \| `HTMLElement` \| `Array<string \| HTMLElement>` | The DOM node(s) or ID selector(s) to convert. Can be a single element/selector or an array for multi-slide export. |
|
|
191
|
-
| `options` | `object` | Configuration object. |
|
|
192
|
-
|
|
193
|
-
**Options Object:**
|
|
194
|
-
|
|
195
|
-
| Key | Type | Default | Description |
|
|
196
|
-
| :---------------- | :------- | :------------- | :-------------------------------------------- |
|
|
197
|
-
| `fileName` | `string` | `"slide.pptx"` | The name of the downloaded file. |
|
|
198
|
-
| `backgroundColor` | `string` | `null` | Force a background color for the slide (hex). |
|
|
199
|
-
|
|
200
|
-
## Important Notes
|
|
201
|
-
|
|
202
|
-
1. **CORS Images:** Because this library uses HTML5 Canvas to process rounded images, any external images must be served with `Access-Control-Allow-Origin: *` headers. If an image is "tainted" (CORS blocked), the browser will refuse to read its data, and it may appear blank in the PPTX.
|
|
203
|
-
2. **Layout System:** The library does not "read" Flexbox or Grid definitions directly. Instead, it lets the browser render the layout, measures the final `x, y, width, height` (BoundingBox) of every element, and places them absolutely on the slide. This ensures 100% visual accuracy regardless of the layout method used.
|
|
204
|
-
3. **Fonts:** PPTX files use the fonts installed on the viewer's OS. If you use a web font like "Inter", and the user doesn't have it installed, PowerPoint will fallback to Arial.
|
|
205
|
-
|
|
206
|
-
## License
|
|
207
|
-
|
|
208
|
-
MIT © [Atharva Dharmendra Jagtap](https://github.com/atharva9167j) and `dom-to-pptx` contributors.
|
|
209
|
-
|
|
210
|
-
## Acknowledgements
|
|
211
|
-
|
|
212
|
-
This project is built on top of [PptxGenJS](https://github.com/gitbrent/PptxGenJS). Huge thanks to the PptxGenJS maintainers and all contributors — dom-to-pptx leverages and extends their excellent work on PPTX generation.
|
|
213
|
-
|
|
214
|
-
## Bundle & Dependencies
|
|
215
|
-
|
|
216
|
-
Starting with v1.0.
|
|
217
|
-
|
|
218
|
-
- If you use npm / a bundler, run:
|
|
219
|
-
|
|
220
|
-
```bash
|
|
221
|
-
npm install dom-to-pptx
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
- For direct browser usage (single script tag), use the bundled file that already includes `pptxgenjs` and `html2canvas`:
|
|
225
|
-
|
|
226
|
-
```html
|
|
227
|
-
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"></script>
|
|
228
|
-
<script>
|
|
229
|
-
domToPptx.exportToPptx('#slide-container', { fileName: 'report.pptx' });
|
|
230
|
-
</script>
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
If you prefer to manage `pptxgenjs` yourself (smaller bundle), the legacy `dist/dom-to-pptx.min.js` remains available and expects `pptxgenjs` to be loaded separately.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
```
|
|
1
|
+
# dom-to-pptx
|
|
2
|
+
|
|
3
|
+
**The High-Fidelity HTML to PowerPoint Converter (v1.0.6).**
|
|
4
|
+
|
|
5
|
+
Most HTML-to-PPTX libraries fail when faced with modern web design. They break on gradients, misalign text, ignore rounded corners, or simply take a screenshot (which isn't editable).
|
|
6
|
+
|
|
7
|
+
**dom-to-pptx** is different. It is a **Coordinate Scraper & Style Engine** that traverses your DOM, calculates the exact computed styles of every element (Flexbox/Grid positions, complex gradients, shadows), and mathematically maps them to native PowerPoint shapes and text boxes. The result is a fully editable, vector-sharp presentation that looks exactly like your web view.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
### 🎨 Advanced Visual Fidelity
|
|
12
|
+
|
|
13
|
+
- **Complex Gradients:** Includes a built-in CSS Gradient Parser that converts `linear-gradient` strings (with multiple stops, angles, and transparency) into vector SVGs for perfect rendering. This now also supports `text-fill-color` gradients, falling back to the first color for broad compatibility.
|
|
14
|
+
- **Mathematically Accurate Shadows:** Converts CSS Cartesian shadows (`x`, `y`, `blur`) into PowerPoint's Polar coordinate system (`angle`, `distance`) for 1:1 depth matching.
|
|
15
|
+
- **Anti-Halo Image Processing:** Uses off-screen HTML5 Canvas with `source-in` composite masking to render rounded images without the ugly white "halo" artifacts found in other libraries.
|
|
16
|
+
- **Soft Edges/Blurs:** Accurately translates CSS `filter: blur()` into PowerPoint's soft-edge effects, preserving visual depth.
|
|
17
|
+
|
|
18
|
+
### 📐 Smart Layout & Typography
|
|
19
|
+
|
|
20
|
+
- **Auto-Scaling Engine:** Build your slide in HTML at **1920x1080** (or any aspect ratio). The library automatically calculates the scaling factor to fit it perfectly into a standard 16:9 PowerPoint slide (10 x 5.625 inches) with auto-centering.
|
|
21
|
+
- **Rich Text Blocks:** Handles mixed-style text (e.g., **bold** spans inside a normal paragraph) while sanitizing HTML source code whitespace (newlines/tabs) to prevent jagged text alignment.
|
|
22
|
+
- **Font Stack Normalization:** Automatically maps web-only fonts (like `ui-sans-serif`, `system-ui`) to safe system fonts (`Arial`, `Calibri`) to ensure the file opens correctly on any computer.
|
|
23
|
+
- **Text Transformations:** Supports CSS `text-transform: uppercase/lowercase` and `letter-spacing` (converted to PT).
|
|
24
|
+
|
|
25
|
+
### ⚡ Technical Capabilities
|
|
26
|
+
|
|
27
|
+
- **Z-Index Handling:** Respects DOM order for correct layering of elements.
|
|
28
|
+
- **Border Radius Math:** Calculates perfect corner rounding percentages based on element dimensions.
|
|
29
|
+
- **Client-Side:** Runs entirely in the browser. No server required.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install dom-to-pptx
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
This library is intended for use in the browser (React, Vue, Svelte, Vanilla JS, etc.).
|
|
40
|
+
|
|
41
|
+
### 1. Basic Example
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { exportToPptx } from 'dom-to-pptx';
|
|
45
|
+
|
|
46
|
+
// Note: If you are using a module bundler, it is recommended to import pptxgenjs
|
|
47
|
+
// directly into your project to ensure tree-shaking and optimal bundle size.
|
|
48
|
+
// import PptxGenJS from 'pptxgenjs'; // Uncomment and use if needed for your setup
|
|
49
|
+
|
|
50
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
51
|
+
// Pass the CSS selector of the container you want to turn into a slide
|
|
52
|
+
await exportToPptx('#slide-container', {
|
|
53
|
+
fileName: 'slide-presentation.pptx',
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Multi-Slide Example
|
|
59
|
+
|
|
60
|
+
To export multiple HTML elements as separate slides, pass an array of elements or selectors:
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import { exportToPptx } from 'dom-to-pptx'; // ESM or CJS import
|
|
64
|
+
|
|
65
|
+
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
66
|
+
const slideElements = document.querySelectorAll('.slide');
|
|
67
|
+
await exportToPptx(Array.from(slideElements), {
|
|
68
|
+
fileName: 'multi-slide-presentation.pptx',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3. Browser Usage (single-file bundle or legacy setup)
|
|
74
|
+
|
|
75
|
+
You can use `dom-to-pptx` directly in the browser in two ways:
|
|
76
|
+
|
|
77
|
+
- Recommended — Single-file bundle (includes runtime deps):
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<!-- Single script that contains dom-to-pptx + pptxgenjs + html2canvas -->
|
|
81
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"></script>
|
|
82
|
+
<script>
|
|
83
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
84
|
+
// The library is available globally as `domToPptx`
|
|
85
|
+
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can also load the bundle from a CDN (unpkg/jsdelivr):
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
<script src="https://unpkg.com/dom-to-pptx@latest/dist/dom-to-pptx.bundle.js"></script>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- Legacy — Explicit runtime includes (smaller dom-to-pptx file, you manage deps):
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<!-- Load pptxgenjs first -->
|
|
100
|
+
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
|
|
101
|
+
<!-- html2canvas is required by the legacy dom-to-pptx build for backdrop-filter and canvas image processing -->
|
|
102
|
+
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
|
103
|
+
<!-- Then load the legacy dom-to-pptx file that expects the above libs -->
|
|
104
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.min.js"></script>
|
|
105
|
+
<script>
|
|
106
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
107
|
+
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
108
|
+
});
|
|
109
|
+
</script>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Notes:
|
|
113
|
+
|
|
114
|
+
- The standalone `dist/dom-to-pptx.bundle.js` includes `pptxgenjs` and `html2canvas`, so you only need one script tag.
|
|
115
|
+
- If you prefer a smaller payload and already have `pptxgenjs` on the page, use the legacy `dist/dom-to-pptx.min.js` and load `pptxgenjs` first.
|
|
116
|
+
|
|
117
|
+
### 4. Recommended HTML Structure
|
|
118
|
+
|
|
119
|
+
### Recommended HTML Structure
|
|
120
|
+
|
|
121
|
+
For the best results, treat your container as a fixed-size canvas. We recommend building your slide at **1920x1080px**. The library will handle the downscaling.
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<!-- Container (16:9 Aspect Ratio) -->
|
|
125
|
+
<!-- The library will capture this background color/gradient automatically -->
|
|
126
|
+
<div
|
|
127
|
+
id="slide-container"
|
|
128
|
+
class="slide w-[1000px] h-[562px] bg-white mx-auto shadow-xl relative overflow-hidden rounded-lg flex items-center justify-center p-10"
|
|
129
|
+
>
|
|
130
|
+
<div
|
|
131
|
+
class="w-full max-w-3xl bg-white rounded-2xl shadow-xl overflow-hidden grid md:grid-cols-2 items-center
|
|
132
|
+
border-l-2 border-indigo-500"
|
|
133
|
+
>
|
|
134
|
+
<div class="p-12">
|
|
135
|
+
<h2 class="text-xl font-semibold text-indigo-500 uppercase tracking-wide mb-2">
|
|
136
|
+
Core Concept
|
|
137
|
+
</h2>
|
|
138
|
+
<h3 class="text-4xl font-bold text-slate-800 mb-6">From Bit to Qubit</h3>
|
|
139
|
+
<div class="space-y-6 text-slate-600">
|
|
140
|
+
<div class="flex items-start gap-4">
|
|
141
|
+
<div
|
|
142
|
+
class="flex-shrink-0 w-8 h-8 bg-slate-200 rounded-full flex items-center justify-center font-bold text-slate-700"
|
|
143
|
+
>
|
|
144
|
+
B
|
|
145
|
+
</div>
|
|
146
|
+
<div>
|
|
147
|
+
<h4 class="font-bold text-slate-700">Classical Bit</h4>
|
|
148
|
+
<p>
|
|
149
|
+
A fundamental unit of information that is either
|
|
150
|
+
<span class="font-semibold text-indigo-600">0</span> or
|
|
151
|
+
<span class="font-semibold text-indigo-600">1</span>.
|
|
152
|
+
</p>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
<div class="flex items-start gap-4">
|
|
156
|
+
<div
|
|
157
|
+
class="flex-shrink-0 w-8 h-8 bg-indigo-200 rounded-full flex items-center justify-center font-bold text-indigo-700"
|
|
158
|
+
>
|
|
159
|
+
Q
|
|
160
|
+
</div>
|
|
161
|
+
<div>
|
|
162
|
+
<h4 class="font-bold text-slate-700">Quantum Bit (Qubit)</h4>
|
|
163
|
+
<p>
|
|
164
|
+
Can be <span class="font-semibold text-indigo-600">0</span>,
|
|
165
|
+
<span class="font-semibold text-indigo-600">1</span>, or a
|
|
166
|
+
<span class="font-semibold text-indigo-600">superposition</span>
|
|
167
|
+
of both states simultaneously.
|
|
168
|
+
</p>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
<div class="h-64 md:h-full">
|
|
174
|
+
<img
|
|
175
|
+
src="https://picsum.photos/800/600?random=2"
|
|
176
|
+
alt="Stylized representation of a qubit"
|
|
177
|
+
class="w-full h-full object-cover"
|
|
178
|
+
/>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## API
|
|
185
|
+
|
|
186
|
+
### `exportToPptx(elementOrSelector, options)`
|
|
187
|
+
|
|
188
|
+
| Parameter | Type | Description |
|
|
189
|
+
| :------------------ | :---------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| `elementOrSelector` | `string` \| `HTMLElement` \| `Array<string \| HTMLElement>` | The DOM node(s) or ID selector(s) to convert. Can be a single element/selector or an array for multi-slide export. |
|
|
191
|
+
| `options` | `object` | Configuration object. |
|
|
192
|
+
|
|
193
|
+
**Options Object:**
|
|
194
|
+
|
|
195
|
+
| Key | Type | Default | Description |
|
|
196
|
+
| :---------------- | :------- | :------------- | :-------------------------------------------- |
|
|
197
|
+
| `fileName` | `string` | `"slide.pptx"` | The name of the downloaded file. |
|
|
198
|
+
| `backgroundColor` | `string` | `null` | Force a background color for the slide (hex). |
|
|
199
|
+
|
|
200
|
+
## Important Notes
|
|
201
|
+
|
|
202
|
+
1. **CORS Images:** Because this library uses HTML5 Canvas to process rounded images, any external images must be served with `Access-Control-Allow-Origin: *` headers. If an image is "tainted" (CORS blocked), the browser will refuse to read its data, and it may appear blank in the PPTX.
|
|
203
|
+
2. **Layout System:** The library does not "read" Flexbox or Grid definitions directly. Instead, it lets the browser render the layout, measures the final `x, y, width, height` (BoundingBox) of every element, and places them absolutely on the slide. This ensures 100% visual accuracy regardless of the layout method used.
|
|
204
|
+
3. **Fonts:** PPTX files use the fonts installed on the viewer's OS. If you use a web font like "Inter", and the user doesn't have it installed, PowerPoint will fallback to Arial.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT © [Atharva Dharmendra Jagtap](https://github.com/atharva9167j) and `dom-to-pptx` contributors.
|
|
209
|
+
|
|
210
|
+
## Acknowledgements
|
|
211
|
+
|
|
212
|
+
This project is built on top of [PptxGenJS](https://github.com/gitbrent/PptxGenJS). Huge thanks to the PptxGenJS maintainers and all contributors — dom-to-pptx leverages and extends their excellent work on PPTX generation.
|
|
213
|
+
|
|
214
|
+
## Bundle & Dependencies
|
|
215
|
+
|
|
216
|
+
Starting with v1.0.6 `dom-to-pptx` ships a standalone browser bundle that includes runtime dependencies (for convenience).
|
|
217
|
+
|
|
218
|
+
- If you use npm / a bundler, run:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npm install dom-to-pptx
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- For direct browser usage (single script tag), use the bundled file that already includes `pptxgenjs` and `html2canvas`:
|
|
225
|
+
|
|
226
|
+
```html
|
|
227
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"></script>
|
|
228
|
+
<script>
|
|
229
|
+
domToPptx.exportToPptx('#slide-container', { fileName: 'report.pptx' });
|
|
230
|
+
</script>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
If you prefer to manage `pptxgenjs` yourself (smaller bundle), the legacy `dist/dom-to-pptx.min.js` remains available and expects `pptxgenjs` to be loaded separately.
|
|
234
|
+
|
|
235
|
+
### Notes for bundler users (Vite / Rollup / Webpack)
|
|
236
|
+
|
|
237
|
+
- **ESM/CJS builds keep `pptxgenjs` external.**
|
|
238
|
+
- The module outputs (`dist/dom-to-pptx.mjs` and `dist/dom-to-pptx.cjs`) _do not_ bundle `pptxgenjs` so that modern bundlers (like Vite) won't accidentally inline Node-only shims from that dependency. This keeps the ESM artifact safe for browser toolchains but requires you to have `pptxgenjs` installed in your project when using the module imports:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
npm install dom-to-pptx pptxgenjs
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
- **If you get pre-bundling errors in Vite** (e.g., esbuild complaining about `https`, `stream`, or other Node built-ins), either install `pptxgenjs` in your app or use the provided standalone UMD bundle.
|
|
245
|
+
|
|
246
|
+
- **Vite quick-workarounds**:
|
|
247
|
+
1. Use the bundled UMD in your dev server by adding a resolve alias in `vite.config.js`:
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
import { defineConfig } from 'vite';
|
|
251
|
+
|
|
252
|
+
export default defineConfig({
|
|
253
|
+
resolve: {
|
|
254
|
+
alias: {
|
|
255
|
+
'dom-to-pptx': '/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
2. Or exclude the package from Vite's dependency optimizer (temporary):
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
// vite.config.js
|
|
265
|
+
export default {
|
|
266
|
+
optimizeDeps: {
|
|
267
|
+
exclude: ['dom-to-pptx'],
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Using the standalone bundle is the simplest path for direct browser usage; using the module build is best for app projects that manage dependencies themselves.
|
|
273
|
+
|
|
274
|
+
Legacy usage note:
|
|
275
|
+
|
|
276
|
+
```html
|
|
277
|
+
<!-- Load pptxgenjs first -->
|
|
278
|
+
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
|
|
279
|
+
<!-- html2canvas is required by the legacy dom-to-pptx build for backdrop-filter and canvas image processing -->
|
|
280
|
+
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
|
281
|
+
<!-- Then load the legacy dom-to-pptx file that expects the above libs -->
|
|
282
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.min.js"></script>
|
|
283
|
+
<script>
|
|
284
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
285
|
+
await domToPptx.exportToPptx('#slide-container', { fileName: 'dashboard-report.pptx' });
|
|
286
|
+
});
|
|
287
|
+
</script>
|
|
288
|
+
```
|