@panayiotis
- If you need to get the actual dimension of the SVG document, we can offer use next sample of code:
static RectangleF GetDocumentRect(SVGDocument document)
{
var rect = new RectangleF(0, 0, 0, 0);
foreach (var item in document.RootElement.ChildNodes)
{
var gr = item as SVGGraphicsElement;
if (gr != null)
{
var m = gr.Transform.AnimVal.Aggregate(new Matrix(),
(m1, m2) =>
{
m1.Multiply(new Matrix(m2.Matrix.A, m2.Matrix.B, m2.Matrix.C, m2.Matrix.D, m2.Matrix.E, m2.Matrix.F));
return m1;
});
rect = RectangleF.Union(rect, Transform(m, gr.GetBBox()));
}
}
return rect;
}
Class SVGGraphicsElement
has method GetBBox which return actual bounding box for this elements.
- If your purpose is the creation of a result Image, PDF, XPS document which size is equal to the size of the original SVG document then you can use the next code:
using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
{
var options = new PdfRenderingOptions()
{
PageSetup =
{
Sizing = SizingType.FitContent
}
};
using (var device = new PdfDevice(options, dataDir + "smiley_out.pdf"))
{
document.RenderTo(device);
}
}
More information about page sizing can be found here: https://apireference.aspose.com/svg/net/aspose.svg.rendering/sizingtype
In case you still face any issues, please share your sample SVG with an expected output image. We will test the scenario in our environment and address it accordingly.