We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add different header for first page in a PDF document

Platform: WinForms |
Control: PDF
Tags: header, pdf

By creating different PdfSection objects for the first page and other pages, different header can be added for first page in a Pdf document.

Assemblies Required




The below code snippet illustrates how to add different header for first page.

Code Snippet:

// Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
PdfSection section1 = document.Sections.Add();
//Add the first page using first section
//Add the section
PdfSection section2 = document.Sections.Add();
RectangleF rect = new RectangleF(0, 0, document.Pages[0].GetClientSize().Width, 140);
//create the template
PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
header.Graphics.DrawRectangle(PdfPens.Red, rect);
header.Graphics.DrawString("First Page Header", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), PdfBrushes.Red, new PointF(10, 10));
section1.Template.Top = header;
//create the template
PdfPageTemplateElement header1 = new PdfPageTemplateElement(rect);
header1.Graphics.DrawRectangle(PdfPens.Red, rect);
header1.Graphics.DrawString("Header Template", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), PdfBrushes.Red, new PointF(10, 10));
section2.Template.Top = header1;
// Save and close the document.


The working sample can be downloaded from the below link:






2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile