public void Render(IRenderingEngine engine,SvgRenderOptions options)
Public Sub Render( _ByVal engine As IRenderingEngine, _ByVal options As SvgRenderOptions _)
public:void Render(IRenderingEngine^ engine,SvgRenderOptions^ options)
engine
Rendering engine to use for the target device. Cannot be null.
options
Options to use during rendering. Can be null.
For more information, refer to SVG Rendering.
Use Rasterize to render this SVG document into the surface of a LEADTOOLS Leadtools.RasterImage object.
This method will throw an exception if this document is not flat (the value of IsFlat is false) or if it does not have valid physical (pixel) bounds (the value of Bounds.IsValid is false).
If the value of options is null, then the following default options will be used:
| Member | Value |
|---|---|
| SvgRenderOptions.Bounds |
The current physical bounds of document (Bounds.Bounds) |
| SvgRenderOptions.ClipBounds |
Empty rectangle for rendering the document |
| SvgRenderOptions.Transform |
Identity Leadtools.LeadMatrix |
| SvgRenderOptions.UseBackgroundColor |
true |
| BackgroundColor |
White color |
This example will convert a page from a PDF file to SVG format and render it on a form.
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.Forms.DocumentWriters;using Leadtools.Svg;using LeadtoolsExamples.Common;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(ImagesPath.Path, "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();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DrawingImports Leadtools.Forms.DocumentWritersImports Leadtools.SvgPublic Shared Sub SvgDocumentRenderExample()' Create a form with a picture boxDim form As New Form()Dim pictureBox As New PictureBox()pictureBox.Dock = DockStyle.Fillform.Controls.Add(pictureBox)Dim document As SvgDocument = Nothing' Load a page from a document file as SVGDim srcFileName As String = Path.Combine(Common.ImagesPath.Path, "Leadtools.pdf")Using codecs As New RasterCodecs()' Set 300 as the default value for loading document filescodecs.Options.RasterizeDocument.Load.Resolution = 300document = DirectCast(codecs.LoadSvg(srcFileName, 1, Nothing), SvgDocument)End Using' Make sure the document is valid for renderingIf Not document.IsFlat Thendocument.Flat(Nothing)End IfIf Not document.Bounds.IsValid Thendocument.CalculateBounds(False)End If' Optimize it for rendering to increase the speeddocument.BeginRenderOptimize()Console.WriteLine("IsRenderOptimized is " + document.IsRenderOptimized.ToString())' This is our paint codeAddHandler pictureBox.Paint,Sub(sender As Object, e As PaintEventArgs)Dim graphics As Graphics = e.Graphics' We will fit and center this SVG document in the client area of the picture boxDim dstBounds As Rectangle = pictureBox.ClientRectangleIf dstBounds.Width < 1 OrElse dstBounds.Height < 1 ThenReturnEnd If' Create the transformation matrixDim transform As LeadMatrix = LeadMatrix.IdentityDim srcBounds As LeadRectD = document.Bounds.Bounds' Calculate the zoom so we can fitDim zoom As Double = 1.0If dstBounds.Width > dstBounds.Height Thenzoom = dstBounds.Width / srcBounds.WidthIf (zoom * srcBounds.Height) > dstBounds.Height Thenzoom = dstBounds.Height / srcBounds.HeightEnd IfElsezoom = dstBounds.Height / srcBounds.HeightIf (zoom * srcBounds.Width) > dstBounds.Width Thenzoom = dstBounds.Width / srcBounds.WidthEnd IfEnd If' We have the zoom factor, set it in the transformtransform.Scale(zoom, zoom)' CenterDim xOffset As Double = (dstBounds.Width - (zoom * srcBounds.Width)) / 2.0Dim yOffset As Double = (dstBounds.Height - (zoom * srcBounds.Height)) / 2.0transform.Translate(xOffset, yOffset)' Now setup the rendering optionsDim options As New SvgRenderOptions()' All of the documentoptions.Bounds = srcBounds' 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 = Trueoptions.BackgroundColor = RasterColor.FromKnownColor(RasterKnownColor.White)' Create a rendering engineUsing engine As IRenderingEngine = RenderingEngineFactory.Create(graphics)' Render the documentdocument.Render(engine, options)End UsingEnd SubAddHandler form.SizeChanged,Sub(sender As Object, e As EventArgs)pictureBox.Invalidate()End Subform.ShowDialog()document.Dispose()End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
