How to add multiple page number formats in Word document?
Syncfusion Essential DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can add multiple page number formats in the Word document in C#.
Steps to add multiple page number formats in the Word document:
- Create a new C# .NET Core console application project.
- Install the Syncfusion.DocIO.Net.Core NuGet package as a reference to your .NET Core applications from NuGet.org.
- Include the following namespace in the Program.cs file:
C#
using Syncfusion.DocIO; using Syncfusion.DocIO.DLS;
- Use the following code example to add multiple page number formats in the Word document:
C#
//Create a new Word document. using (WordDocument document = new WordDocument()) { //Add a section to the document. IWSection section = document.AddSection(); //Add a page number to the document. section.PageSetup.PageStartingNumber = 1; section.PageSetup.PageNumberStyle = PageNumberStyle.Arabic; //Add a footer paragraph to the document. IWParagraph paragraph = section.HeadersFooters.Footer.AddParagraph(); paragraph.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); //Add a text for the footer paragraph. paragraph.AppendText("Copyright Northwind Inc. 2001 - 2015"); //Add page number field to the document. paragraph.AppendText("\tPage "); paragraph.AppendField("Page", FieldType.FieldPage); //Add a paragraph to a section. paragraph = section.AddParagraph(); //Append the text to the created paragraph. paragraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); //Add a section to the document. section = document.AddSection(); section.PageSetup.PageStartingNumber = 1; section.PageSetup.RestartPageNumbering = true; section.PageSetup.PageNumberStyle = PageNumberStyle.LetterUpper; //Add a paragraph to a section. paragraph = section.AddParagraph(); //Append the text to the created paragraph. paragraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."); //Create a file stream. using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Sample.docx"), FileMode.Create, FileAccess.ReadWrite)) { //Save the Word document to the file stream. document.Save(outputFileStream, FormatType.Docx); } }
A complete working sample to add multiple page number formats in the Word document in C# can be downloaded from GitHub.
By executing the program, you will get the Output document as follows.
Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail merge, merge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.
Explore more about the rich set of Syncfusion Word Framework features.
See Also:
How to copy the HeaderFooter content from one Word document and insert them into first page header footer of another Word document
How to determine the page number of a particular text within a Word document
How to remove empty page at end of Word document
How to merge the sections in an already existing document to a new document
How to insert headers and footers in a document
Is it possible to create different Header and footer in a word document
How to change section break in Word document as page break?
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning about how to add multiple page number formats in Word document.
You can refer to our .NET Core Word library’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET Core Word Library example to understand how to present and manipulate data.
For current customers, you can check out our .NET Core from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET Core Word Library and other .NET Core components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!