Saving SVG to PNG as a specific size

I want to take my SVG file and render it at 32x32. I can render my SVG files as PNGs but they are always massive, is there a way to set a target size? I tried creating a page for the renderer but that just crops the image not scales it. Thanks!

@RobotGizmo

We have logged a feature request as SVG-69 in our issue tracking system for the sake of implementation of your requirements. We will investigate the feasibility and let you know as soon as the required functionality is available. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks for letting me know, I’ll keep an eye out.

@RobotGizmo

A new option Sizing was added to PageSetup class. This option has the enum type SizingType:

namespace Aspose.Svg.Rendering
{
/// <summary>
/// Represents the enumeration of page sizing types.
/// </summary>
///
public enum SizingType
{
/// <summary>
/// Changing given sizes of the page to fit the size of the content it contains.
/// </summary>
FitContent,
/// <summary>
/// Scaling a content size in accordance to the given size of the page.
/// </summary>
ScaleContent,
/// <summary>
/// Fitting the content size to the page size while maintaining the preferred aspect ratio insofar as possible.
/// </summary>
Contain,
/// <summary>
/// Placing the content on page and crop everything that out of given page size.
/// </summary>
Crop
}
}

You can use the next code to get expected behavior with Aspose.SVG for .NET 20.12:

using Aspose.Svg;
using Aspose.Svg.Rendering;
using Aspose.Svg.Rendering.Image;

var options = new ImageRenderingOptions();
options.PageSetup.Sizing = Rendering.SizingType.Contain;
using (var svgDocument = new SVGDocument("src.svg"))
using (var svgRenderer = new SvgRenderer())
using (var device = new ImageDevice(options, "result.png"))
{
svgRenderer.Render(device, svgDocument);
}