//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Svg; namespaceDsPdfWeb.Demos.Basics{// This sample shows how to use the SaveAsSvg() method to save a PDF// page as SVG (scalable vector graphics) image, and how to load// and render that image on a new PDF page. // The PDF used as the source was generated by the SvgSpecArt sample,// but any valid PDF can be used instead.publicclassSaveAsSvg {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage(); var rc = Common.Util.AddNote("We load an existing PDF into a temporary GcPdfDocument, " +"save its first page as an SVG image to a stream, and then " +"draw that image on the page of the resulting PDF.", page); // Load a one page document into a temp PDF:usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "svg-spec-art.pdf"));var docSrc = newGcPdfDocument(); docSrc.Load(fs); // Save the first page of the loaded PDF as SVG:usingvar svgStream = newMemoryStream(); docSrc.Pages[0].SaveAsSvg(svgStream, newSaveAsImageOptions() { BackColor = Color.Transparent });// PDF pages can also be saved as SVGZ (compressed SVG) using the ToSvgz() method:// docSrc.Pages[0].ToSvgz(); svgStream.Position = 0;// Create a GcSvgDocument from the saved SVG so that we can draw it in the resulting PDF:usingvar svgDoc = GcSvgDocument.FromStream(svgStream); // For illustration purposes we render the SVG with transparent background// on a rectangle with a custom fill and border: rc = newRectangleF(0, rc.Bottom, page.Size.Width, page.Size.Height - rc.Bottom); rc.Inflate(-4f, -4f); page.Graphics.DrawRectangle(rc, Color.DarkGoldenrod); page.Graphics.FillRectangle(rc, Color.PaleGoldenrod); page.Graphics.DrawSvg(svgDoc, rc); // Done: doc.Save(stream);return doc.Pages.Count; } }}