How to Start Convert PDF Read PDF Build PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

Using C# PDF SDK
C# PDF Builder: How to add page header and footer to PDF file

C# Demo Code to add page header and footer to adobe pdf file

Add a simple header and footer

String outputFilePath = Program.RootPath + "\\" + "Sample71.pdf";

Document document = new Document();
PDFBuildHandler.Create(document, outputFilePath);


//  create a header
Header header = new Header();
//  set header content
Paragraph headerContent = new Paragraph("This is a header");
//  set header alignment
headerContent.Alignment = Alignment.ALIGN_CENTER;
header.AddParagraph(0, headerContent);

//  create a footer
Footer footer = new Footer();
//  set footer content
Paragraph footerContent = new Paragraph("This is a footer");
//  set footer alignment
footerContent.Alignment = Alignment.ALIGN_RIGHT;
footer.AddParagraph(0, footerContent);

//  set header and footer to the document
HeaderFooterOption hdrftrOps = new HeaderFooterOption();
hdrftrOps.PageRange = HeaderFooterOption.PageRangeMode.All;
document.SetHeaderFooter(header, footer, hdrftrOps);

document.Add(new Paragraph("This is body field."));

//  add a new page (the 2nd page)
//  add a new page (the 3rd page)