Sections.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 GrapeCity.Documents.Word;
  9.  
  10. namespace DsWordWeb.Demos
  11. {
  12. // Shows how to add sections to a document
  13. // and modify the page setup of sections.
  14. public class Sections
  15. {
  16. public GcWordDocument CreateDocx()
  17. {
  18. GcWordDocument doc = new GcWordDocument();
  19.  
  20. var sec1 = doc.Body.Sections.First;
  21. // Change default margins from 1" to 1/2":
  22. sec1.PageSetup.Margin.Left = sec1.PageSetup.Margin.Right =
  23. sec1.PageSetup.Margin.Top = sec1.PageSetup.Margin.Bottom = 36;
  24. var pars1 = sec1.GetRange().Paragraphs;
  25. pars1.Add("Section 1, Paragraph 1. " + Util.LoremIpsumPar());
  26. pars1.Add("Section 1, Paragraph 2. " + Util.LoremIpsumPar());
  27. pars1.Add("Section 1, Paragraph 3. " + Util.LoremIpsumPar());
  28.  
  29. var sec2 = doc.Body.Paragraphs.Last.AddSectionBreak();
  30. // For the 2nd section, change page orientation:
  31. sec2.PageSetup.Size.Orientation = PageOrientation.Landscape;
  32. var pars2 = sec2.GetRange().Paragraphs;
  33. pars2.Add("Section 2, Paragraph 1. " + Util.LoremIpsumPar());
  34. pars2.Add("Section 2, Paragraph 2. " + Util.LoremIpsumPar());
  35. pars2.Add("Section 2, Paragraph 3. " + Util.LoremIpsumPar());
  36.  
  37. // Done:
  38. return doc;
  39. }
  40. }
  41. }
  42.