Load SVG document with options
Leave feedback
On this page
GroupDocs.Conversion provides SvgLoadOptions to control how source SVG (Scalable Vector Graphics) files are processed.
The following options are available:
| Option | Description |
|---|---|
| Format | The document type is auto-detected during loading, but you can explicitly specify the source format as SVG |
| MinimumWidth | Set minimum width for converting SVG document. Used when converting to raster formats. Default value is 800. |
| MinimumHeight | Set minimum height for converting SVG document. Used when converting to raster formats. Default value is 600. |
| CropToContentBounds | Gets or sets a value indicating whether to crop the SVG bounding box to the content bounds before conversion. Default value is false. |
| ExecuteScripts | Whether the document’s scripts run while it loads and converts. Default: false. Available since version 26.10. |
| ExternalResourceHandler | A handler called for each resource the document asks to load; it can allow the resource, skip it or supply its content. Default: null. Available since version 26.10. |
| SkipExternalResources | Whether to skip the external resources the document references, such as linked images and stylesheets. Default: true. Content the document carries, local files inside its folder and resources that match WhitelistedResources still load. |
| WhitelistedResources | Absolute URI prefixes, such as https://cdn.example.com/assets/, of external resources to load while SkipExternalResources is true. Since version 26.10, an entry that is not an absolute URI prefix makes the load fail with InvalidLoadOptionsException. |
NoteSince version 26.10, an SVG or SVGZ document converted without load options getsSvgLoadOptions, so external resources are skipped and scripts do not run unless you allow them. Earlier versions usedPageDescriptionLanguageLoadOptions, which has no external resource control. See Skip loading of external resources.
The following code snippet shows how to load an SVG file with explicit format specification:
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new SvgLoadOptions
{
Format = PageDescriptionLanguageFileType.Svg
};
using (Converter converter = new Converter("vector-graphic.svg", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("vector-graphic.pdf", options);
}
The following code snippet shows how to load an SVG file with custom minimum dimensions for raster format conversion:
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new SvgLoadOptions
{
Format = PageDescriptionLanguageFileType.Svg,
MinimumWidth = 1200,
MinimumHeight = 900
};
using (Converter converter = new Converter("logo.svg", getLoadOptions))
{
ImageConvertOptions options = new ImageConvertOptions
{
Format = ImageFileType.Png
};
converter.Convert("logo.png", options);
}
The following code snippet shows how to load an SVG file with cropping to content bounds:
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new SvgLoadOptions
{
Format = PageDescriptionLanguageFileType.Svg,
CropToContentBounds = true
};
using (Converter converter = new Converter("icon.svg", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("icon.pdf", options);
}
The following code snippet shows how to load an SVG file and convert it to XPS format:
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new SvgLoadOptions
{
Format = PageDescriptionLanguageFileType.Svg
};
using (Converter converter = new Converter("diagram.svg", getLoadOptions))
{
PageDescriptionLanguageConvertOptions options = new PageDescriptionLanguageConvertOptions
{
Format = PageDescriptionLanguageFileType.Xps
};
converter.Convert("diagram.xps", options);
}
The following code snippet shows how to load an SVG file and convert it to a Word document:
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new SvgLoadOptions
{
Format = PageDescriptionLanguageFileType.Svg
};
using (Converter converter = new Converter("infographic.svg", getLoadOptions))
{
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
converter.Convert("infographic.docx", options);
}
The following code snippet shows how to load an SVG file and convert it to HTML:
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new SvgLoadOptions
{
Format = PageDescriptionLanguageFileType.Svg
};
using (Converter converter = new Converter("chart.svg", getLoadOptions))
{
WebConvertOptions options = new WebConvertOptions();
converter.Convert("chart.html", options);
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.