InkXml.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Xml;
  11. using GrapeCity.Documents.Word;
  12.  
  13. namespace DsWordWeb.Demos
  14. {
  15. // This sample shows how to load an existing ink XML
  16. // and create an InkShape with the loaded ink as content.
  17. public class InkXml
  18. {
  19. public GcWordDocument CreateDocx()
  20. {
  21. GcWordDocument doc = new GcWordDocument();
  22.  
  23. // Load the ink XML and add it as an ink shape to the DOCX:
  24. var inkXml = new XmlDocument();
  25. inkXml.Load(Path.Combine("Resources", "Misc", "ink.xml"));
  26. var ink = doc.Body.Paragraphs.Add("Paragraph containing the ink shape.").GetRange().Runs.Add().GetRange().InkShapes.Add(inkXml);
  27. // Modify the ink's size and angle:
  28. ink.WrapFormat.Type = WrapType.Square;
  29. ink.Size.Width.Relative = 40;
  30. ink.Size.Width.RelativeTo = SizeRelativeHorizontally.Margin;
  31. ink.Size.Height.Relative = 30;
  32. ink.Size.Height.RelativeTo = SizeRelativeVertically.Margin;
  33. ink.Rotation.Angle = 30;
  34.  
  35. // Add a paragraph after the one containing the ink:
  36. doc.Body.Paragraphs.Add(
  37. "This paragraph is added after the ink shape loaded from an XML. " +
  38. $"The ink shape's wrap type is set to {ink.WrapFormat.Type} " +
  39. $"and the shape is rotated {ink.Rotation.Angle} degrees clockwise. " +
  40. $"The width is {ink.Size.Width.Relative}% relative to page width sans the margins, " +
  41. $"and the height is {ink.Size.Height.Relative}% relative to page height sans the margins.");
  42.  
  43. // Done:
  44. return doc;
  45. }
  46. }
  47. }
  48.