Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 705071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:00:45+00:00 2026-05-14T04:00:45+00:00

I’m wondering how can I put a header into my PDF file, cause I’ve

  • 0

I’m wondering how can I put a header into my PDF file, cause I’ve tried the tutorials from here:

http://itextsharp.sourceforge.net/tutorial/ch04.html

And it has not worked.

I’ve done this:

Dim head As New HeaderFooter(New Phrase("This is page: "), False)
head.Border = Rectangle.NO_BORDER
document.Header = head

But VS2008 says that HeaderFooter is not defined (line 1), and Footer it's not a member of "iTextSharp.text.document" (line 3).

I’ve already included the imports at the beginning of my code and iIdon’t have any other problems with the iTextsharps (I mean that it is working apart of the header problem):

Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.Data.SQLite
Imports System.IO

So please, can anyone explain to me how can i set a header for my pages?

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:00:45+00:00Added an answer on May 14, 2026 at 4:00 am

    The answer to this question depends on which version of the iTextSharp dll you are using.

    If you are using a version lower than 5, this should work

    Imports iTextSharp.text.pdf
    Imports iTextSharp.text
    Module Module1
        Sub Main()
            Dim pdfWrite As PdfWriter
            Dim pdfDoc As New Document()
            Dim pdfMemoryStream As New IO.FileStream("tryme.pdf", IO.FileMode.Create)
            pdfWrite = PdfWriter.GetInstance(pdfDoc, pdfMemoryStream)
            Dim pdfHeader As New HeaderFooter(New Phrase("Im at the head: "), False)
            pdfHeader.Border = Rectangle.NO_BORDER
            pdfDoc.Header = pdfHeader
            pdfDoc.Open()
            pdfDoc.Add(New Paragraph("Hello World"))
            pdfDoc.NewPage()
            pdfDoc.Add(New Paragraph("Hello World Again"))
            pdfDoc.Close()
        End Sub
    End Module
    

    Update

    For version 5+ of iTextSharp the HeaderFooter property has been removed from iTextSharp. To add Headers/Footers now you must use PageEvents. The following code demonstrates how to do this (very simply!)

    Imports iTextSharp.text.pdf
    Imports iTextSharp.text
    Imports System.IO
    Module Module1
        Sub Main()
            Dim pdfDoc As New Document()
            Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("tryme2.pdf", FileMode.Create))
            Dim ev As New itsEvents
            pdfWrite.PageEvent = ev
            pdfDoc.Open()
            pdfDoc.Add(New Paragraph("Hello World"))
            pdfDoc.NewPage()
            pdfDoc.Add(New Paragraph("Hello World Again"))
            pdfDoc.Close()
        End Sub
    End Module
    
    Public Class itsEvents
        Inherits PdfPageEventHelper
        Public Overrides Sub OnStartPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal document As iTextSharp.text.Document)
            Dim ch As New Chunk("This is my Stack Overflow Header on page " & writer.PageNumber)
            document.Add(ch)
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I have text I am displaying in SIlverlight that is coming from a CMS
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.