Articles in this section
Category / Section

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

1 min read

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

1)Syncfusion.Compression.Base.dll

2)Syncfusion.Pdf.Base.dll

 

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
section1.Pages.Add();
 
 
//Add the section
PdfSection section2 = document.Sections.Add();
 
section2.Pages.Add();
section2.Pages.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.
document.Save("Sample.pdf");
document.Close(true);

 

The working sample can be downloaded from the below link:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfHeaderandFooterSample1996332280

 

 

 

 

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