RenderSvgz.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Collections.Generic;
  10. using GrapeCity.Documents.Pdf;
  11. using GrapeCity.Documents.Text;
  12. using GrapeCity.Documents.Svg;
  13. using GCTEXT = GrapeCity.Documents.Text;
  14. using GCDRAW = GrapeCity.Documents.Drawing;
  15. using DsPdfWeb.Demos.Common;
  16.  
  17. namespace DsPdfWeb.Demos
  18. {
  19. // This sample shows how to render an SVGZ (compressed SVG) image.
  20. // The SVG art used in this sample is from freesvg.org.
  21. public class RenderSvgz
  22. {
  23. public int CreatePDF(Stream stream)
  24. {
  25. var svgPath = Path.Combine("Resources", "SvgMisc", "Smiling-Girl.svgz");
  26. using var svg = GcSvgDocument.FromSvgz(File.ReadAllBytes(svgPath));
  27.  
  28. // Render the image and a border around it:
  29. var doc = new GcPdfDocument();
  30. var g = doc.NewPage().Graphics;
  31. var pt = new PointF(72, 72);
  32. g.DrawSvg(svg, pt);
  33. var sz = svg.GetIntrinsicSize(SvgLengthUnits.Points);
  34. g.DrawRectangle(new RectangleF(pt, sz), Color.MediumPurple);
  35.  
  36. // Done:
  37. doc.Save(stream);
  38. return doc.Pages.Count;
  39. }
  40. }
  41. }
  42.