SvgSpecArt.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. // Use GcSvgDocument to render a few images used as illustrations
  20. // in the SVG spec.
  21. public class SvgSpecArt
  22. {
  23. public int CreatePDF(Stream stream)
  24. {
  25. // Load images from resources:
  26. var fnames = new List<string>() { "dash-path.svg", "opacity.svg", "paths.svg", "shadowstyle.svg", "units.svg", };
  27. var images = new List<(string, GcSvgDocument)>();
  28. foreach (var f in fnames)
  29. images.Add((f, GcSvgDocument.FromFile(Path.Combine("Resources", "SvgSpecArt", f))));
  30.  
  31. const float margin = 36;
  32. const float gapy = 18;
  33. var ip = new PointF(margin, margin);
  34.  
  35. // Render the images:
  36. var doc = new GcPdfDocument();
  37. var g = doc.NewPage().Graphics;
  38. for (int i = 0; i < images.Count(); ++i)
  39. {
  40. var svg = images[i].Item2;
  41. var s = svg.GetIntrinsicSize(SvgLengthUnits.Points);
  42. g.DrawSvg(svg, ip);
  43. ip.Y += s.Height + gapy;
  44. }
  45. // Done:
  46. doc.Save(stream);
  47. // Dispose images after saving the PDF:
  48. images.ForEach(t_ => t_.Item2.Dispose());
  49. return doc.Pages.Count;
  50. }
  51. }
  52. }
  53.