Problem setting Header and footer of a generated PDF

Hello,

I am trying to genearate a PDF with specific Header and footer. I wrote these lines of code but i can not see the header or footer in the PDF generated.

Dim objPDF As Pdf = New Pdf()

Dim section As Section = objPDF.Sections.Add()

Dim headFoot As HeaderFooter = New HeaderFooter(section)

headFoot.Paragraphs.Add(New Text("header/footer"))

headFoot.IsFirstPageOnly = False

headFoot.IsSubsequentPagesOnly = True

section.Paragraphs.Add(New Text("abc"))

Request you to guide me.

Hello Yvette,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for considering Aspose.

I'm not sure how lengthy your PDF document cam be, but as far as I can see from the code snippet, if its a single page document then Header/Footer will not be displayed over it. Because, you've set the property IsFirstPageOnly value to false and also have set the value for IsSubsequentPagesOnly property to true, which indicates that the header must not be displayed over the first page. Please try using the following code snippet to display the Header and Footer over a PDF document with single page. The resultant PDF is also in attachment.

[VB.NET]

'Instantiate Pdf instance by calling it empty constructor
Dim objPDF As Pdf = New Pdf()
'Create a section in the Pdf object
Dim section As Section = objPDF.Sections.Add()

'Create a HeaderSection object and add it to as OddHeader to section object
Dim HeaderSec As HeaderFooter = New HeaderFooter(section)
section.OddHeader = HeaderSec
HeaderSec.Paragraphs.Add(New Text("Sample Header Section"))

Dim
FooterSec As HeaderFooter = New HeaderFooter(section)
FooterSec.Paragraphs.Add(New Text("Sample Footer Section"))
section.OddFooter = FooterSec

' headFoot.IsFirstPageOnly = False
' headFoot.IsSubsequentPagesOnly = True
section.Paragraphs.Add(New Text("abc"))
objPDF.Save("d:/AS/sampleOutput.pdf")

Please take a look over the following link for more information on Set Page Header and Footer

Thanks for your help :slight_smile: