Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

HeaderFooterSample.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /***************************************************************************************
  2. DocX – DocX is the community edition of Xceed Words for .NET
  3. Copyright (C) 2009-2017 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features and fast professional support,
  7. pick up Xceed Words for .NET at https://xceed.com/xceed-words-for-net/
  8. *************************************************************************************/
  9. using System;
  10. using System.IO;
  11. namespace Xceed.Words.NET.Examples
  12. {
  13. public class HeaderFooterSample
  14. {
  15. #region Private Members
  16. private const string HeaderFooterSampleOutputDirectory = Program.SampleDirectory + @"HeaderFooter\Output\";
  17. #endregion
  18. #region Constructors
  19. static HeaderFooterSample()
  20. {
  21. if( !Directory.Exists( HeaderFooterSample.HeaderFooterSampleOutputDirectory ) )
  22. {
  23. Directory.CreateDirectory( HeaderFooterSample.HeaderFooterSampleOutputDirectory );
  24. }
  25. }
  26. #endregion
  27. #region Public Methods
  28. /// <summary>
  29. /// Add three different types of headers and footers to a document.
  30. /// </summary>
  31. public static void HeadersFooters()
  32. {
  33. Console.WriteLine( "\tHeadersFooters()" );
  34. // Create a document.
  35. using( DocX document = DocX.Create( HeaderFooterSample.HeaderFooterSampleOutputDirectory + @"HeadersFooters.docx" ) )
  36. {
  37. // Insert a Paragraph in the first page of the document.
  38. var p1 = document.InsertParagraph("This is the ").Append( "first").Bold().Append(" page Content.");
  39. p1.SpacingBefore( 70d );
  40. p1.InsertPageBreakAfterSelf();
  41. // Insert a Paragraph in the second page of the document.
  42. var p2 = document.InsertParagraph( "This is the " ).Append( "second" ).Bold().Append( " page Content." );
  43. p2.InsertPageBreakAfterSelf();
  44. // Insert a Paragraph in the third page of the document.
  45. var p3 = document.InsertParagraph( "This is the " ).Append( "third" ).Bold().Append( " page Content." );
  46. p3.InsertPageBreakAfterSelf();
  47. // Insert a Paragraph in the third page of the document.
  48. var p4 = document.InsertParagraph( "This is the " ).Append( "fourth" ).Bold().Append( " page Content." );
  49. // Add Headers and Footers to the document.
  50. document.AddHeaders();
  51. document.AddFooters();
  52. // Force the first page to have a different Header and Footer.
  53. document.DifferentFirstPage = true;
  54. // Force odd & even pages to have different Headers and Footers.
  55. document.DifferentOddAndEvenPages = true;
  56. // Insert a Paragraph into the first Header.
  57. document.Headers.First.InsertParagraph("This is the ").Append("first").Bold().Append(" page header");
  58. // Insert a Paragraph into the first Footer.
  59. document.Footers.First.InsertParagraph( "This is the " ).Append( "first" ).Bold().Append( " page footer" );
  60. // Insert a Paragraph into the even Header.
  61. document.Headers.Even.InsertParagraph( "This is an " ).Append( "even" ).Bold().Append( " page header" );
  62. // Insert a Paragraph into the even Footer.
  63. document.Footers.Even.InsertParagraph( "This is an " ).Append( "even" ).Bold().Append( " page footer" );
  64. // Insert a Paragraph into the odd Header.
  65. document.Headers.Odd.InsertParagraph( "This is an " ).Append( "odd" ).Bold().Append( " page header" );
  66. // Insert a Paragraph into the odd Footer.
  67. document.Footers.Odd.InsertParagraph( "This is an " ).Append( "odd" ).Bold().Append( " page footer" );
  68. // Add the page number in the first Footer.
  69. document.Footers.First.InsertParagraph("Page #").AppendPageNumber( PageNumberFormat.normal );
  70. // Add the page number in the even Footers.
  71. document.Footers.Even.InsertParagraph( "Page #" ).AppendPageNumber( PageNumberFormat.normal );
  72. // Add the page number in the odd Footers.
  73. document.Footers.Odd.InsertParagraph( "Page #" ).AppendPageNumber( PageNumberFormat.normal );
  74. document.Save();
  75. Console.WriteLine( "\tCreated: HeadersFooters.docx\n" );
  76. }
  77. }
  78. #endregion
  79. }
  80. }