This example shows one method of adding headers and footers.

 

   

Setup
 

First, we create an ABCpdf Doc object and define the content we're going to be adding.

Set theDoc = Server.CreateObject("ABCpdf12.Doc")
theText = "Gallia est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes..." ' truncated for clarity

 

   

Content
 

We set up the style for our content.

We need to specify the Rect defining the area in which content will be inserted, a color (red) and a font size.

We add the text using the same method as employed in the Text Flow Example. We draw a frame round our content area each time so we can see how the text has been positioned.

theDoc.Rect = "100 200 500 600"
theDoc.Color = "255 0 0"
theDoc.FontSize = 24
theID = theDoc.AddHtml(theText)
theDoc.FrameRect
While theDoc.Chainable(theID)
  theDoc.Page = theDoc.AddPage()
  theID = theDoc.AddHtml("", theID)
  theDoc.FrameRect
Wend
theCount = theDoc.PageCount

 

   

Header
 

We set up the style for our header.

We need to specify the Rect defining the area in which the header will be inserted, a color (green) and a font size. We use the HPos and VPos parameters to center the text both horizontally and vertically.

We then iterate through the pages in the document adding headers as we go. We frame our headers so we can see the header area.

theDoc.Rect = "100 650 500 750"
theDoc.HPos = 0.5
theDoc.VPos = 0.5
theDoc.Color = "0 255 0"
theDoc.FontSize = 36
For i = 1 To theCount
  theDoc.PageNumber = i
  theDoc.AddText "De Bellum Gallicum"
  theDoc.FrameRect
Next

 

   

Footer
 

We set up the style for our footer.

We need to specify the Rect defining the area in which the footer will be inserted, a color (blue) and a font size. We use the HPos and VPos parameters to center the text vertically and align it to the right.

We then iterate through the pages in the document adding footers as we go. We frame our footers so we can see the footer area.

theDoc.Rect = "100 50 500 150"
theDoc.HPos = 1.0
theDoc.VPos = 0.5
theDoc.Color = "0 0 255"
theDoc.FontSize = 36
theCount = theDoc.PageCount
For i = 1 To theCount
  theDoc.PageNumber = i
  theDoc.AddText "Page " & i & " of " & theCount
  theDoc.FrameRect
Next

 

   

Save
 

Finally, we save the PDF.

theDoc.Save "c:\mypdfs\headerfooter.pdf"
theDoc.Clear

 

   

Results
 

headerfooter.pdf [Page 1]

headerfooter.pdf [Page 2]

headerfooter.pdf [Page 3]

headerfooter.pdf [Page 4]