RenderSvg.cs
// // This code is part of Document Solutions for PDF demos. // Copyright (c) MESCIUS inc. All rights reserved. // using System; using System.IO; using System.Drawing; using System.Linq; using System.Collections.Generic; using GrapeCity.Documents.Pdf; using GrapeCity.Documents.Text; using GrapeCity.Documents.Svg; using GCTEXT = GrapeCity.Documents.Text; using GCDRAW = GrapeCity.Documents.Drawing; using DsPdfWeb.Demos.Common; namespace DsPdfWeb.Demos { // This short sample shows how to measure and render an SVG image. // Note that when an SVG is rendered on GcPdfGraphics, it is NOT rasterized, // so the image quality is preserved if the SVG is scaled up or down. // // The SVG art used in this sample is from freesvg.org. public class RenderSvg { public int CreatePDF(Stream stream) { // Load the SVG: var svgPath = Path.Combine("Resources", "SvgClipArt", "Smiling-Girl.svg"); using var svg = GcSvgDocument.FromFile(svgPath); // Measure and render the image: var doc = new GcPdfDocument(); var g = doc.NewPage().Graphics; var pt = new PointF(g.Resolution, g.Resolution); var rc = new RectangleF(pt, svg.GetIntrinsicSize(SvgLengthUnits.Points)); // Draw the SVG and a border around it: g.DrawSvg(svg, pt); g.DrawRectangle(rc, Color.DarkGray); // Done: doc.Save(stream); return doc.Pages.Count; } } }