@turbodocx/html-to-docx 1.17.0 → 1.18.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 CHANGED
@@ -15,6 +15,15 @@ Convert HTML to Word, Google Docs, and DOCX files with the fastest, most reliabl
15
15
 
16
16
  Based on the original work and assisted by the original contributors of [privateOmega/html-to-docx](https://github.com/privateOmega/html-to-docx), this library is now actively maintained and enhanced by TurboDocx, ensuring continuous improvements and long-term support for production environments.
17
17
 
18
+ ## 🌐 Explore the TurboDocx Ecosystem
19
+
20
+ | Package | Links | Description |
21
+ |---------|-------|-------------|
22
+ | n8n-nodes-turbodocx | [![npm](https://img.shields.io/npm/v/@turbodocx/n8n-nodes-turbodocx?logo=npm&logoColor=white&label=npm)](https://www.npmjs.com/package/@turbodocx/n8n-nodes-turbodocx) [![GitHub](https://img.shields.io/github/stars/turbodocx/n8n-nodes-turbodocx?style=social)](https://github.com/turbodocx/n8n-nodes-turbodocx) | n8n community node for TurboDocx API & TurboSign |
23
+ <!-- | turbodocx | [![npm](https://img.shields.io/npm/v/turbodocx?logo=npm&logoColor=white&label=npm)](https://www.npmjs.com/package/turbodocx) | TurboDocx Node.js SDK | -->
24
+ <!-- | turbodocx-python | [![PyPI](https://img.shields.io/pypi/v/turbodocx?logo=python&logoColor=white&label=pypi)](https://pypi.org/project/turbodocx/) | TurboDocx Python SDK | -->
25
+ <!-- | turbodocx-ruby | [![Gem](https://img.shields.io/gem/v/turbodocx?logo=ruby&logoColor=white&label=gem)](https://rubygems.org/gems/turbodocx) | TurboDocx Ruby SDK | -->
26
+
18
27
  ## Why @turbodocx/html-to-docx?
19
28
 
20
29
  🚀 **Lightning Fast Performance** - Pure JavaScript implementation with no dependencies on headless browsers or external binaries. Perfect for AI applications that need rapid document generation.
@@ -247,6 +256,9 @@ full fledged examples can be found under `example/`
247
256
  - `minImageSize` <?[Number]> minimum image size in bytes. Defaults to `1024` (1KB).
248
257
  - `maxCacheSize` <?[Number]> maximum total cache size in bytes (LRU cache limit to prevent OOM). Defaults to `20971520` (20MB).
249
258
  - `maxCacheEntries` <?[Number]> maximum number of unique images in cache (LRU eviction). Defaults to `100`.
259
+ - `svgHandling` <?[String]> strategy for handling SVG images. Defaults to `'convert'`. Options:
260
+ - `'convert'` - Converts SVG to PNG for maximum compatibility with all Word versions (requires `sharp` package)
261
+ - `'native'` - Embeds SVG natively for Office 2019+ (preserves vector quality)
250
262
  - `footerHTMLString` <[String]> clean html string equivalent of footer. Defaults to `<p></p>` if footer flag is `true`.
251
263
 
252
264
  ### Returns
@@ -280,6 +292,130 @@ Also you could add attribute `data-start="n"` to start the numbering from the n-
280
292
  `<ol data-start="2">` will start the numbering from ( B. b. II. ii. 2. )
281
293
 
282
294
 
295
+ ## SVG Image Support
296
+
297
+ The library provides comprehensive SVG image support with two strategies to fit your needs:
298
+
299
+ ### Installation & Package Size
300
+
301
+ The library supports SVG images with [`sharp`](https://sharp.pixelplumbing.com/) as an optional peer dependency for high-quality SVG→PNG conversion.
302
+
303
+ **Basic Installation** (Lightweight):
304
+ ```bash
305
+ npm install @turbodocx/html-to-docx
306
+ ```
307
+ - **Package size**: ~2.8MB (sharp not included)
308
+ - **Compatibility**: SVGs embedded natively - requires Office 2019+ or Microsoft 365
309
+ - **Best for**: Modern-only environments or size-constrained deployments (Lambda, Edge)
310
+ - **Auto-fallback**: Library automatically uses native SVG mode when sharp is unavailable
311
+
312
+ **Full Installation** (Maximum Compatibility - Recommended):
313
+ ```bash
314
+ npm install @turbodocx/html-to-docx sharp
315
+ ```
316
+ - **Base package**: ~2.8MB
317
+ - **With sharp**: Additional ~34MB (platform-specific native binaries)
318
+ - **Compatibility**: Converts SVGs to PNG - works with all Word versions (2007+)
319
+ - **Best for**: Production applications requiring broad compatibility
320
+
321
+ #### Why is sharp optional?
322
+
323
+ Sharp is a native Node.js module that provides the best SVG to PNG conversion quality, but adds ~34MB of platform-specific native binaries to your `node_modules`. We've made it an optional peer dependency so you can choose:
324
+
325
+ | Configuration | Install Command | Size | SVG Handling | Word Compatibility | Use Case |
326
+ |--------------|-----------------|------|--------------|-------------------|----------|
327
+ | **Without sharp** (default) | `npm install @turbodocx/html-to-docx` | 2.8MB | Native SVG | Office 2019+ only | Modern environments, Lambda/edge functions |
328
+ | **With sharp** (recommended) | `npm install @turbodocx/html-to-docx sharp` | 2.8MB + 34MB binaries | PNG conversion | All versions (2007+) | Production apps, broad compatibility |
329
+
330
+ The library **gracefully handles both scenarios** - if sharp is unavailable, SVGs are automatically embedded in native format.
331
+
332
+ ### 1. Convert to PNG (Default - Maximum Compatibility)
333
+
334
+ By default, SVG images are automatically converted to PNG format for maximum compatibility with all Word versions (requires `sharp`):
335
+
336
+ ```javascript
337
+ const htmlWithSVG = `
338
+ <div>
339
+ <img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIj48Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgZmlsbD0iIzM0OThkYiIvPjwvc3ZnPg==" alt="Circle">
340
+ </div>
341
+ `;
342
+
343
+ // Default behavior - SVG converted to PNG
344
+ const docx = await HTMLtoDOCX(htmlWithSVG);
345
+
346
+ // Or explicitly set to convert
347
+ const docx = await HTMLtoDOCX(htmlWithSVG, null, {
348
+ imageProcessing: {
349
+ svgHandling: 'convert' // Converts SVG to PNG (default)
350
+ }
351
+ });
352
+ ```
353
+
354
+ **Benefits:**
355
+ - ✅ Works with all Word versions (2007+)
356
+ - ✅ Compatible with Word Online, Google Docs, LibreOffice
357
+ - ✅ No compatibility warnings or errors
358
+
359
+ ### 2. Native SVG (Office 2019+ Only)
360
+
361
+ For modern Office environments, you can embed SVG images natively to preserve vector quality:
362
+
363
+ ```javascript
364
+ const htmlWithSVG = `
365
+ <div>
366
+ <img src="data:image/svg+xml;base64,..." alt="Vector Graphic">
367
+ </div>
368
+ `;
369
+
370
+ const docx = await HTMLtoDOCX(htmlWithSVG, null, {
371
+ imageProcessing: {
372
+ svgHandling: 'native' // Embed SVG natively (Office 2019+)
373
+ }
374
+ });
375
+ ```
376
+
377
+ **Benefits:**
378
+ - ✅ Perfect vector quality at any zoom level
379
+ - ✅ Smaller file sizes for complex graphics
380
+ - ✅ Editable in modern Office applications
381
+
382
+ **Requirements:**
383
+ - Microsoft Office 2019 or later
384
+ - Microsoft 365
385
+ - Word for Mac 2019+
386
+
387
+ **Note:** Older Word versions will show an "unreadable content" error with native SVG. Use `'convert'` mode for backwards compatibility.
388
+
389
+ ### Handling SVG Without Sharp
390
+
391
+ If `sharp` is not installed (e.g., using `--no-optional`), the library automatically falls back to native SVG embedding:
392
+
393
+ ```javascript
394
+ // Even with svgHandling: 'convert', if sharp unavailable → uses native SVG
395
+ const docx = await HTMLtoDOCX(htmlWithSVG, null, {
396
+ imageProcessing: {
397
+ svgHandling: 'convert', // Tries to convert, falls back to native
398
+ suppressSharpWarning: false, // Set to true to suppress warning when sharp is missing
399
+ verboseLogging: true // Shows: "Sharp not available, using native SVG"
400
+ }
401
+ });
402
+ ```
403
+
404
+ **No crashes, no errors** - the library detects sharp availability at runtime and adjusts automatically:
405
+
406
+ ```bash
407
+ # With sharp installed
408
+ ✅ SVG → PNG conversion → Works in Word 2007+
409
+
410
+ # Without sharp (--no-optional)
411
+ ℹ️ SVG → Native embedding → Works in Office 2019+ only
412
+
413
+ # Suppress the warning (if intentionally using native SVG mode)
414
+ imageProcessing: { suppressSharpWarning: true }
415
+ ```
416
+
417
+ **Pro tip**: For serverless/Lambda deployments with size constraints, install without sharp and set `suppressSharpWarning: true` to avoid console warnings. Document that generated files require Office 2019+.
418
+
283
419
  ## RTL (Right-to-Left) Language Support
284
420
 
285
421
  The library also supports RTL languages like Arabic and Hebrew. Use the `direction` option to enable RTL text flow: