-
-
Notifications
You must be signed in to change notification settings - Fork 593
Open
Description
Summary
This issue proposes adding a static convenience method ImageRun.fromSvg() to simplify creating SVG images with required raster fallbacks.
Motivation
SVG support already exists in the library (via type: "svg" with a fallback property), but creating SVG images requires verbose configuration. A helper method would improve developer experience while maintaining the declarative API pattern.
Proposed API
const image = ImageRun.fromSvg(
Buffer.from(svgContent, "utf-8"),
{ type: "png", data: pngFallbackData },
{ width: 200, height: 150 }
);FromSvgOptions
| Property | Type | Required | Description |
|---|---|---|---|
| width | number | Yes | Width in pixels |
| height | number | Yes | Height in pixels |
| flip | object | No | Horizontal/vertical flip |
| rotation | number | No | Rotation in degrees |
| floating | IFloating | No | Floating positioning |
| altText | DocPropertiesOptions | No | Accessibility text |
| outline | OutlineOptions | No | Border/outline |
Implementation
I have a working implementation on a fork that includes:
FromSvgOptionstype definitionImageRun.fromSvg()static method with JSDoc documentation- Unit tests covering various input types and transformations
- Integration tests for end-to-end DOCX generation with SVG
- Demo file (
demo/97-svg-images.ts) showcasing features - Documentation updates for
docs/usage/images.md
Compatibility
- SVG rendering requires Word 2019+ or Microsoft 365
- The required fallback image displays in older Word versions or alternative viewers (LibreOffice, etc.)
Related
This builds on the existing SVG support in the library and follows the declarative API pattern used throughout.
Happy to submit a PR if there's interest in this feature.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels