@turbodocx/html-to-docx 1.18.1 → 1.20.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/README.md +151 -1
- package/dist/html-to-docx.browser.js +17 -0
- package/dist/html-to-docx.esm.js +2 -2
- package/dist/html-to-docx.umd.js +2 -2
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -19,6 +19,10 @@ Based on the original work and assisted by the original contributors of [private
|
|
|
19
19
|
|
|
20
20
|
| Package | Links | Description |
|
|
21
21
|
|---------|-------|-------------|
|
|
22
|
+
| API & SDK | [](https://www.turbodocx.com/products/api-and-sdk) | Production-ready SDK for e-signature, document generation, template processing, and more |
|
|
23
|
+
| TurboSign | [](https://www.turbodocx.com/products/api-and-sdk) | Digital signature API for seamless e-signature workflows |
|
|
24
|
+
| sdk | [](https://github.com/TurboDocx/sdk) | Official TurboDocx SDK for seamless API integration |
|
|
25
|
+
| next-plugin-llms | [](https://github.com/TurboDocx/next-plugin-llms) | Next.js plugin for automatic llms.txt generation |
|
|
22
26
|
| n8n-nodes-turbodocx | [](https://www.npmjs.com/package/@turbodocx/n8n-nodes-turbodocx) [](https://github.com/turbodocx/n8n-nodes-turbodocx) | n8n community node for TurboDocx API & TurboSign |
|
|
23
27
|
<!-- | turbodocx | [](https://www.npmjs.com/package/turbodocx) | TurboDocx Node.js SDK | -->
|
|
24
28
|
<!-- | turbodocx-python | [](https://pypi.org/project/turbodocx/) | TurboDocx Python SDK | -->
|
|
@@ -171,6 +175,148 @@ This will generate two DOCX files in the `example/typescript` directory:
|
|
|
171
175
|
- `basic-example.docx` - A simple document with minimal configuration
|
|
172
176
|
- `advanced-example.docx` - A document with headers, footers, and advanced formatting options
|
|
173
177
|
|
|
178
|
+
## Browser Standalone Build
|
|
179
|
+
|
|
180
|
+
The library provides a standalone browser build that bundles all dependencies into a single file. This allows you to use the library directly in HTML pages without any build tools or module bundlers.
|
|
181
|
+
|
|
182
|
+
### Build Outputs
|
|
183
|
+
|
|
184
|
+
When you run `npm run build`, three distribution files are generated:
|
|
185
|
+
|
|
186
|
+
| File | Format | Size | Dependencies | Use Case |
|
|
187
|
+
|------|--------|------|--------------|----------|
|
|
188
|
+
| `dist/html-to-docx.esm.js` | ES Module | ~1.6 MB | External | Modern bundlers (Webpack, Vite, Rollup) |
|
|
189
|
+
| `dist/html-to-docx.umd.js` | UMD | ~1.6 MB | External | Node.js, AMD, or manual dependency management |
|
|
190
|
+
| `dist/html-to-docx.browser.js` | IIFE | ~2.4 MB | **All bundled** | Direct browser usage, CDN, quick prototypes |
|
|
191
|
+
|
|
192
|
+
### Build Commands
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Build all versions (ESM + UMD + Browser)
|
|
196
|
+
npm run build
|
|
197
|
+
|
|
198
|
+
# Build only the browser standalone version (development)
|
|
199
|
+
npm run build:browser
|
|
200
|
+
|
|
201
|
+
# Build only the browser standalone version (production, minified)
|
|
202
|
+
npm run build:browser:prod
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Browser Usage
|
|
206
|
+
|
|
207
|
+
Include the standalone browser build directly in your HTML:
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
<!DOCTYPE html>
|
|
211
|
+
<html>
|
|
212
|
+
<head>
|
|
213
|
+
<title>HTML to DOCX Demo</title>
|
|
214
|
+
</head>
|
|
215
|
+
<body>
|
|
216
|
+
<!--
|
|
217
|
+
Polyfills for Node.js globals (required)
|
|
218
|
+
Note: While rollup-plugin-polyfill-node bundles most Node.js polyfills,
|
|
219
|
+
these runtime globals must be set before the library loads because
|
|
220
|
+
some dependencies check for them synchronously during initialization.
|
|
221
|
+
-->
|
|
222
|
+
<script>
|
|
223
|
+
if (typeof global === 'undefined') window.global = window;
|
|
224
|
+
if (typeof process === 'undefined') window.process = { env: {} };
|
|
225
|
+
if (typeof Buffer === 'undefined') {
|
|
226
|
+
window.Buffer = {
|
|
227
|
+
from: function(data, encoding) {
|
|
228
|
+
if (typeof data === 'string') {
|
|
229
|
+
// Handle base64 and utf-8 encoding
|
|
230
|
+
if (encoding === 'base64') {
|
|
231
|
+
var binary = atob(data);
|
|
232
|
+
var bytes = new Uint8Array(binary.length);
|
|
233
|
+
for (var i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
234
|
+
return bytes;
|
|
235
|
+
}
|
|
236
|
+
return new TextEncoder().encode(data);
|
|
237
|
+
}
|
|
238
|
+
return new Uint8Array(data);
|
|
239
|
+
},
|
|
240
|
+
isBuffer: function() { return false; }
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
</script>
|
|
244
|
+
|
|
245
|
+
<!-- Include the standalone browser build -->
|
|
246
|
+
<script src="path/to/html-to-docx.browser.js"></script>
|
|
247
|
+
|
|
248
|
+
<script>
|
|
249
|
+
async function generateDocument() {
|
|
250
|
+
const htmlContent = `
|
|
251
|
+
<h1>Hello World</h1>
|
|
252
|
+
<p>This is a <strong>test document</strong> generated in the browser.</p>
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
const result = await HTMLToDOCX(htmlContent, null, {
|
|
257
|
+
title: 'My Document',
|
|
258
|
+
creator: 'Browser App'
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Convert result to Blob for download
|
|
262
|
+
let blob;
|
|
263
|
+
if (result instanceof Blob) {
|
|
264
|
+
blob = result;
|
|
265
|
+
} else if (result instanceof ArrayBuffer || result instanceof Uint8Array) {
|
|
266
|
+
blob = new Blob([result], {
|
|
267
|
+
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Trigger download
|
|
272
|
+
const url = URL.createObjectURL(blob);
|
|
273
|
+
const a = document.createElement('a');
|
|
274
|
+
a.href = url;
|
|
275
|
+
a.download = 'document.docx';
|
|
276
|
+
a.click();
|
|
277
|
+
URL.revokeObjectURL(url);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.error('Error generating DOCX:', error);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
</script>
|
|
283
|
+
|
|
284
|
+
<button onclick="generateDocument()">Generate DOCX</button>
|
|
285
|
+
</body>
|
|
286
|
+
</html>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Testing the Browser Build
|
|
290
|
+
|
|
291
|
+
A test page is included to verify the browser build works correctly:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Build and start the test server
|
|
295
|
+
npm run test:browser
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Then open http://localhost:8080/tests/test_browser.html in your browser.
|
|
299
|
+
|
|
300
|
+
The test page allows you to:
|
|
301
|
+
- Edit HTML content in a textarea
|
|
302
|
+
- Click "Generate DOCX" to create and download a Word document
|
|
303
|
+
- See status messages for success or errors
|
|
304
|
+
|
|
305
|
+
### CDN Usage
|
|
306
|
+
|
|
307
|
+
You can also host the browser build on a CDN for easy inclusion:
|
|
308
|
+
|
|
309
|
+
```html
|
|
310
|
+
<!-- Example: Self-hosted or CDN -->
|
|
311
|
+
<script src="https://your-cdn.com/html-to-docx/1.18.1/html-to-docx.browser.js"></script>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Limitations in Browser Environment
|
|
315
|
+
|
|
316
|
+
- **Sharp (SVG conversion)**: The `sharp` image processing library is not available in browsers. SVG images will be embedded natively (requires Office 2019+).
|
|
317
|
+
- **File System**: No direct file system access. Documents are returned as Blob/ArrayBuffer for download.
|
|
318
|
+
- **Image URLs**: Remote images must be CORS-enabled or converted to base64 data URLs.
|
|
319
|
+
|
|
174
320
|
## Usage
|
|
175
321
|
|
|
176
322
|
```js
|
|
@@ -487,4 +633,8 @@ Made with [contrib.rocks](https://contrib.rocks).
|
|
|
487
633
|
|
|
488
634
|
---
|
|
489
635
|
|
|
490
|
-
|
|
636
|
+
<div align="center">
|
|
637
|
+
|
|
638
|
+
[](https://www.turbodocx.com)
|
|
639
|
+
|
|
640
|
+
</div>
|