Configure SVG image support strategies
developThe library supports two SVG handling strategies via the imageProcessing.svgHandling option. Choosing between them depends on your deployment constraints and target Word version compatibility.
1. Convert to PNG (Maximum Compatibility)
Converts SVGs to PNG format. This is the recommended approach for production applications that need to support all versions of Microsoft Word (including 2007+), Word Online, and Google Docs.
Requirement: Requires sharp to be installed as a peer dependency.
2. Native SVG (Modern Office Only)
Embeds SVGs natively to preserve vector quality and reduce file size. Requirement: Only works with Microsoft Office 2019+, Microsoft 365, or Word for Mac 2019+. Warning: Older Word versions will display an "unreadable content" error if native SVGs are used.
Automatic Fallback
If sharp is not installed, the library will automatically fall back to native SVG embedding even if you have configured svgHandling: 'convert'.
// Example: Explicitly setting SVG handling to 'convert' (requires sharp)
const docx = await HTMLtoDOCX(htmlWithSVG, null, {
imageProcessing: {
svgHandling: 'convert'
}
});
// Example: Explicitly setting SVG handling to 'native' (Office 2019+ only)
const docx = await HTMLtoDOCX(htmlWithSVG, null, {
imageProcessing: {
svgHandling: 'native'
}
});