Load SVG document with options

GroupDocs.Conversion provides SvgLoadOptions to control how source SVG (Scalable Vector Graphics) files are processed.

The following options are available:

OptionDescription
FormatThe document type is auto-detected during loading, but you can explicitly specify the source format as SVG
MinimumWidthSet minimum width for converting SVG document. Used when converting to raster formats. Default value is 800.
MinimumHeightSet minimum height for converting SVG document. Used when converting to raster formats. Default value is 600.
CropToContentBoundsGets or sets a value indicating whether to crop the SVG bounding box to the content bounds before conversion. Default value is false.
ExecuteScriptsWhether the document’s scripts run while it loads and converts. Default: false. Available since version 26.10.
ExternalResourceHandlerA 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.
SkipExternalResourcesWhether 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.
WhitelistedResourcesAbsolute 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.
Note
Since version 26.10, an SVG or SVGZ document converted without load options gets SvgLoadOptions, so external resources are skipped and scripts do not run unless you allow them. Earlier versions used PageDescriptionLanguageLoadOptions, which has no external resource control. See Skip loading of external resources.

Load SVG file

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);
}

Load SVG with custom dimensions

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);
}

Load SVG with crop to content bounds

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);
}

Convert SVG to page description language format

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);
}

Convert SVG to Word document

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);
}

Convert SVG to HTML

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);
}
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.