Articles in this section
Category / Section

How do I insert headers and footers in a Winforms document?

2 mins read

 

In Winforms DocIO,  Section Headers and Footers property is used to set the document headers and footers. We can insert document elements like images and tables inside the header and footer. Here is a code snippet that demonstrates the usage.

C#

 // Creating a new document.

WordDocument doc = new WordDocument();

// Add a new section to the document.

IWSection section = doc.AddSection();

// Add a new paragraph for header to the document.

 IWParagraph headerPar = new WParagraph(doc);

 // Add the paragraph to the header section.

section.HeadersFooters.Header.Paragraphs.Add(headerPar);

// Add a new paragraph for header to the document.

IWParagraph footerPar = new WParagraph(doc);

 // Add the paragraph to the Footer section. section.HeadersFooters.Footer.Paragraphs.Add(footerPar)

 

VB

 '' Creating a new document.

Dim doc As WordDocument = New WordDocument()

'' Add a new section to the document.

Dim section As IWSection = doc.AddSection()

'' Add a new paragraph for header to the document.

Dim headerPar As IWParagraph = New WParagraph(doc)

'' Add the paragraph to the header section.

CType(section.HeadersFooters.Header.Paragraphs, WParagraphCollection).Add(headerPar)

'' Add the paragraph to the Footer section.

CType(section.HeadersFooters.Footer.Paragraphs, WParagraphCollection).Add(footerPar)

 

You can download a complete working sample from GitHub


Conclusion

I hope you enjoyed learning about how to insert  headers and footers in a document.

You can refer to our Winforms DocIO feature tour page to know about its other groundbreaking feature representations. You can also explore our Winforms DocIO documentation to understand how to present and manipulate data. 

For current customers, you can check out our Winforms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Winforms DocIO and other Winforms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied