public LeadMatrix Transform { get; set; }
The transformation to be applied when rendering the document. The default value is LeadMatrix.Identity.
This is a Leadtools.LeadMatrix instance that you can use to apply zooming, translation and rotation to the final document. The value of Transform will be applied to Bounds to calculate the final destination rectangle in pixels.
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.Forms.DocumentWriters;using Leadtools.Svg;using Leadtools.Document.Writer;public void SvgDocumentRenderExample(){// Create a form with a picture boxForm form = new Form();PictureBox pictureBox = new PictureBox();pictureBox.Dock = DockStyle.Fill;form.Controls.Add(pictureBox);SvgDocument document = null;// Load a page from a document file as SVGstring srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf");using (var codecs = new RasterCodecs()){// Set 300 as the default value for loading document filescodecs.Options.RasterizeDocument.Load.Resolution = 300;document = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument;}// Make sure the document is valid for renderingif (!document.IsFlat)document.Flat(null);if (!document.Bounds.IsValid)document.CalculateBounds(false);// Optimize it for rendering to increase the speeddocument.BeginRenderOptimize();Console.WriteLine("IsRenderOptimized is " + document.IsRenderOptimized);// This is our paint codepictureBox.Paint += (sender, e) =>{Graphics graphics = e.Graphics;// We will fit and center this SVG document in the client area of the picture boxRectangle dstBounds = pictureBox.ClientRectangle;if (dstBounds.Width < 1 || dstBounds.Height < 1)return;// Create the transformation matrixLeadMatrix transform = LeadMatrix.Identity;LeadRectD srcBounds = document.Bounds.Bounds;// Calculate the zoom so we can fitdouble zoom = 1.0;if (dstBounds.Width > dstBounds.Height){zoom = dstBounds.Width / srcBounds.Width;if ((zoom * srcBounds.Height) > dstBounds.Height)zoom = dstBounds.Height / srcBounds.Height;}else{zoom = dstBounds.Height / srcBounds.Height;if ((zoom * srcBounds.Width) > dstBounds.Width)zoom = dstBounds.Width / srcBounds.Width;}// We have the zoom factor, set it in the transformtransform.Scale(zoom, zoom);// Centerdouble xOffset = (dstBounds.Width - (zoom * srcBounds.Width)) / 2.0;double yOffset = (dstBounds.Height - (zoom * srcBounds.Height)) / 2.0;transform.Translate(xOffset, yOffset);// Now setup the rendering optionsSvgRenderOptions options = new SvgRenderOptions();// Use our transformoptions.Transform = transform;// clipping (if any)options.ClipBounds = LeadRectD.Create(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);// Fill the background with a white coloroptions.UseBackgroundColor = true;options.BackgroundColor = RasterColor.FromKnownColor(RasterKnownColor.White);options.Bounds = srcBounds;// Create a rendering engineusing (var engine = RenderingEngineFactory.Create(graphics)){// Render the documentdocument.Render(engine, options);}};form.SizeChanged += (sender, e) => pictureBox.Invalidate();form.ShowDialog();document.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";}