How to Start Convert 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

VB.NET PDF Editor Library
How to add, edit PDF file page header, footer using vb.net


An Excellent PDF Control Allows VB.NET Developers to add or delete header/footer/page number to PDF File in VB.NET









  • Professional PDF SDK for Visual Studio .NET, which able to add header, footer, page number in vb.net class
  • Advanced PDF edit control and component for modify header, footer, page number in both vb.net WinForms
  • Free online sample code for quick evaluation in Visual Basic .net framework for PDF page header, footer
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Easy to add/remove header, footer to/from PDF page online in browser in ASP.NET web project
  • Support to copy a PDF page header, footer to another PDF file page in .NET framework
  • Support to add different headers/footers to PDF file.




VB.NET:Define Header and Footer regions



Using XDoc.PDF library, the region of header and footer is defined through Page Margins as follows:

  1. Header : The area surrounded by Left, Right and Top Margin.
  2. Footer : The area surrounded by Left, Right and Bottom Margin.


The header/footer region can be devided into 3 PDFPageTextField (Left/Center/Right).
You can define text font and text color through PDFPageTextField object.
The region and location of header/footer are as follows:





Add Header & Footer to PDF File using VB.NET


You can add, insert fixed text message (such as document title, author name etc.) to page header & footer fields , you can also add message with one or more dynamic field tokens. It supports two dynamic field tokens: automatic page number, and date.

A dynamic field token must be in form "<<***>>".

For Automatic Page Number

  1. <<1>> : Page number only.
  2. <<1/n>> : Page number and total page count, with separator '/'.


For Date

  1. <<m/d>> : Month and day, with separator '/'.
  2. <<m/d/yy>> : Month, day and year, with separator '/'.
  3. <<m/d/yyyy>> : Month, day and year, with separator '/'.
  4. <<mm/dd/yy>> : Month, day and year, with separator '/'.
  5. <<mm/dd/yyyy>> : Month, day and year, with separator '/'.
  6. <<d/m/yy>> : Day, month and year, with separator '/'.
  7. <<d/m/yyyy>> : Day, month and year, with separator '/'.
  8. <<dd/mm/yy>> : Day, month and year, with separator '/'.
  9. <<dd/mm/yyyy>> : Day, month and year, with separator '/'.
  10. <<mm/yy>> : Month and year, with separator '/'.
  11. <<mm/yyyy>> : Month and year, with separator '/'.
  12. <<m.d.yy>> : Month, day and year, with separator '.'.
  13. <<m.d.yyyy>> : Month, day and year, with separator '.'.
  14. <<mm.dd.yy>> : Month, day and year, with separator '.'.
  15. <<mm.dd.yyyy>> : Month, day and year, with separator '.'.
  16. <<mm.yy>> : Month and year, with separator '.'.
  17. <<mm.yyyy>> : Month and year, with separator '.'.
  18. <<d.m.yy>> : Day, month and year, with separator '.'.
  19. <<d.m.yyyy>> : Day, month and year, with separator '.'.
  20. <<dd.mm.yy>> : Day, month and year, with separator '.'.
  21. <<dd.mm.yyyy>> : Day, month and year, with separator '.'.
  22. <<yy-mm-dd>> : Year, month and day, with separator '-'.
  23. <<yyyy-mm-dd>> : Year, month and day, with separator '-'.


The following demo code will explain how to add header or footer to PDF file using VB.NET.



Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\1_hdrftr.pdf"

' open a PDF file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)


' define a header/footer setting
Dim hdrftr1 As PDFPageHeaderFooter = New PDFPageHeaderFooter()
' set center header field
hdrftr1.CenterHeaderField.Set("Title: *****", New Font("Arial", 12.0F, FontStyle.Regular), Color.Black)
' set left footer field
hdrftr1.LeftFooterField.Set("Page <<1/n>>", New Font("Arial", 9.0F, FontStyle.Regular), Color.DarkGray)

' define page range all odd pages
Dim pageRange1 As PageRangeOptions = New PageRangeOptions()
pageRange1.AllPages = True
pageRange1.Subset = PageRangeSubset.Odd

' apply header/footer settings to all odd pages
PDFPageFieldHandler.ApplyHeaderFooter(doc, hdrftr1, pageRange1)

' define a header/footer setting
Dim hdrftr2 As PDFPageHeaderFooter = New PDFPageHeaderFooter()
' set center header field
hdrftr2.CenterHeaderField.Set("Title: *****", New Font("Arial", 12.0F, FontStyle.Regular), Color.Black)
' set right footer field
hdrftr2.RightFooterField.Set("Page <<1/n>>", New Font("Arial", 9.0F, FontStyle.Regular), Color.DarkGray)

' define page range all even pages
Dim pageRange2 As PageRangeOptions = New PageRangeOptions()
pageRange2.AllPages = True
pageRange2.Subset = PageRangeSubset.Even

' apply header/footer settings to all even pages
PDFPageFieldHandler.ApplyHeaderFooter(doc, hdrftr2, pageRange2)

doc.Save(outputFilePath)




Remove all Page Header/Footer settings in a PDF document object using VB.NET


Dim inputFilePath As String = "C:\1_hdrftr.pdf"
Dim outputFilePath As String = "C:\output.pdf"

Dim doc As PDFDocument = New PDFDocument(inputFilePath)
PDFPageFieldHandler.RemoveHeaderFooters(doc)
doc.Save(outputFilePath)




Retrieve all Page Header/Footer settings from a PDF file using vb.net


Dim inputFilePath As String = "C:\1_hdrftr.pdf"

Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' get all Header/Footer settings in the document
Dim info As PDFPageHeaderFooterInfo = PDFPageFieldHandler.RetreiveHeaderFooters(doc)

' get default setting for Header/Footer And Page Range
Dim defaultSetting As PDFPageHeaderFooter = info.GetDefaultSetting()
Dim defaultPageRange As PageRangeOptions = info.GetDefaultPageRangeSettings()