PDF Header and Footer

Pdf

Create custom Headers and Footers for any of your documents

Creating Header and Footer for PDF documents is now easy

What is PDF?

  • PDF (short for Portable Document Format) is a reasonably standard text file format of Adobe Systems. Similar to the Word (.doc) format, PDF supports raw text (text) along with fonts, graphic images, sounds, and many other effects. However, displaying PDF documents does not depend on the working environment of the user (machine configuration, software, and operating system).

PDF's history

  • PDF - Portable Document Format, is a mobile document format. Adobe first released it in the early 90s as a way to store documents entirely in a file. Because at the time, the site was still in its infancy when PDFs were in development, their primary uses are for publishing desktop print documents. Companies use PDFs to store posters, leaflets, and other similar files for physical printing.
  • It takes a long time for PDF to continue. PDF didn't have all of the built-in features available today, and using dial-up access to download a large PDF file was extremely slow. After a few years, Adobe released Adobe Reader for free for all, and PDF eventually defeated some competitors to become the standard file for fixed documents. More interestingly, PDF was originally a proprietary format, meaning Adobe controls the PDF and how it works. But in 2008, they abandoned this ownership, and PDF became an open standard. Now PDF files still have a set of essential properties, but they are independent of Adobe. Indeed, you can find dozens of other PDF readers and editors.

How PDF?

  • To know why PDF was so revolutionary when it came out, we had to understand what the standard was at the time. In the early 90's, professional software used to design graphics and documents led to large files being unbearable, especially when we embed them with images, fonts, and text. Remember that computers during this time only have a fraction of the processing power of the computer you are using today, meaning that every bit of performance is essential.
  • To overcome this problem, software developers started using links to other resources on the computer. Let's say you used unique fonts in your document. Instead of saving all the data for this font inside your record, it will pull the necessary information from the font settings folder on your computer. This method will reduce the load on the document file, making it lighter.
  • Everything will work fine as long as you do not move the font on the computer. However, if you take the file to another computer without installing your particular font, it will not look like it anymore. You can imagine the pain of spending all the time creating an important document and then having it look awful because you didn't keep links to graphic elements exist. PDF files have changed this. Adobe has found a way to assemble all the parts of a file and make it smaller. This new method is a far more effective way than the solution developers used before PDF was available on the market. That's why PDF has become a standard.

Why PDF?

  • The portability of PDF is crucial. The PDF files look the same no matter which device do we open them. Whether you're using Windows 10, Mac, Chrome OS, Android, Windows Phone, iPad or Windows XP - for any software and hardware, PDF files are always suitable. Information in PDF does not depend on the device of the creator or the viewer. Include fonts, images, charts, and it doesn't seem to be a problem.
  • Compare when you send a Microsoft Word document to someone. What happens if the recipient doesn't have Microsoft Word on his/her computer? Sure, they can open it with Google Docs, but the document might look very different because Docs displays files differently. If you spend a dozen of time creating tables, images, and other elements and it may not be as original. And what if they try to open a Word document on their phone?
  • As a general rule, PDF files are for viewing. What you see when you click Save is what other recipients see. And you don't even need to install a reader - most modern browsers can open PDFs without a problem. While you can edit PDFs, you are limited to a few free options unless you have to pay for premium software like Adobe Acrobat, Foxit PhantomPDF, or Nitro Reader.

Why is PDF still so popular?

  • Besides the portability described above, PDF files carry several other features that have contributed to their popularity.
  • PDF files allow fine-tuned security settings. When creating a PDF, you can turn off the ability to print, leave comments, or copy the text of the viewer. Therefore, when governments and businesses place forms online, they can significantly restrict them to prevent abuse. For added security, you can also protect it with a PDF password.
  • You may have noticed that PDFs also work with fill fields. PDF creators can place highlighted blocks anywhere in the document to show where they want the recipient to add information. Even if they have restricted editing, viewers can still enter names, addresses, and other pertinent information into these fields. PDFs support digital signing, so you can add your approval to a document without having to print it out.
  • Small features like adding comments, bookmarks, stamps, hyperlinks, and other live content have kept PDF files relevant for up to the current decade. Optical recognition software can capture documents and quickly turn them into PDF files, and some independent publishers even offer books as PDF files. Ease of use, rich feature set, and popularity have kept PDF necessary in everyday computing life.
  • So, you have learned about how PDF started, how it works, and what makes it so famous and popular. In a world of different operating systems, screen sizes, browsers, and hardware components, PDFs remain firm and unchanged. They let you know for sure that the document you created will not undergo any strange changes when the recipient sees it. That's what PDF offers, and that's why it has been the standard for more than two decades.

What is a Header?

  • The header in PDF documents is a method that helps you mark your copyright in a particular paragraph of text, which means that you will highlight your work.
  • Depending on your Adobe version, there are different ways to create a header. And this you absolutely can watch live at online videos. And in most subjects or projects, the Header insertion is considered very important. It helps you create emphasis and can quickly help viewers understand what you want to send to.

What is a Footer?

  • What is Footer? Many know, but some who do not. The Footer is the bottom of a document, which is the end of a page within that document. Footer also has many types.
  • Usually the Footer will display the following information:
  • Author
  • Number of pages
  • Copyright
  • Etc.
  • In short, every document that has a header and footer helps in explaining the topic and make all the pages connected in a record.

Example

  • Interacting with PDF documents on .NET platform will undoubtedly cause many difficulties for programmers. Especially changing the document structure, as well as adding, deleting, or editing Header and Footer of any document.
  • Worry no more because from now on, you will be supported, rocket speed with PDF Office Component library. And next, we will illustrate how to create a PDF document as well as add Header and Footer.
  • First of all, you will need to create yourself a PDF document. You can take advance of the PdfDocument class that implemented in the PDF Office Component:
  • C# Version: PdfDocument doc = new PdfDocument();
  • VB Version: Dim doc As New PdfDocument()
  • Next, you may want to add some informative attributes to your document:
  • C# Version:
    doc.DocumentInformation.Author = "OfficeComponent";
    doc.DocumentInformation.Producer = "OfficeComponent";
    doc.DocumentInformation.Creator = "OfficeComponent";
    doc.DocumentInformation.Title = Title;
  • VB Version:
    doc.DocumentInformation.Author = "OfficeComponent"
    doc.DocumentInformation.Producer = "OfficeComponent"
    doc.DocumentInformation.Creator = "OfficeComponent"
    doc.DocumentInformation.Title = Title
  • Adding some new pages as well as setting format settings will end the process of initializing your document:
  • C# Version:
    //Add a page
    PdfPage page = doc.Pages.Add();

    //Create font
    PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 11.5f);
    
    Font ttf = new Font("Calibri", 14f, FontStyle.Bold);
    PdfTrueTypeFont heading = new PdfTrueTypeFont(ttf, true);
  • VB Version:
    'Add a page
    Dim page As PdfPage = doc.Pages.Add()

    'Create font
    Dim font As New PdfStandardFont(PdfFontFamily.Helvetica, 11.5F)

    Dim ttf As New Font("Calibri", 14F, FontStyle.Bold)
    Dim heading As New PdfTrueTypeFont(ttf, True)
  • Adding Header and Footer from here will become extremely fast with two methods: AddHeader() and AddFooter():
  • C# Version:
    //Adding Header
    AddHeader(doc, "OfficeComponent OfficeComponentPdf", "Header and Footer Demo");

    //Adding Footer
    AddFooter(doc, "@Copyright " + DateTime.Now.Year);

- **VB Version:**

    'Adding Header
    AddHeader(doc, "OfficeComponent OfficeComponentPdf", "Header and Footer Demo")

    'Adding Footer
    AddFooter(doc, "@Copyright " & Date.Now.Year)
  • A complete program would look like this:
  • C# Version:
    // Create a new instance of PdfDocument class.
            PdfDocument doc = new PdfDocument();


            // Set document's information.
            doc.DocumentInformation.Author = "OfficeComponent";
            doc.DocumentInformation.Producer = "OfficeComponent";
            doc.DocumentInformation.Creator = "OfficeComponent";
            doc.DocumentInformation.Title = Title;

            //Add a page
            PdfPage page = doc.Pages.Add();

            //Create font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 11.5f);

            Font ttf = new Font("Calibri", 14f, FontStyle.Bold);
            PdfTrueTypeFont heading = new PdfTrueTypeFont(ttf, true);

            //Adding Header
            AddHeader(doc, "OfficeComponent OfficeComponentPdf", "Header and Footer Demo");

            //Adding Footer
            AddFooter(doc, "@Copyright " + DateTime.Now.Year);

            //Set formats
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Justify;
            string expath = CommonDataPath + "\\About.txt";
            StreamReader reader = new StreamReader(expath, Encoding.ASCII);
            string text = reader.ReadToEnd();
            reader.Close();

            RectangleF column = new RectangleF(0, 20, page.Graphics.ClientSize.Width - 10f, page.Graphics.ClientSize.Height);
            _bounds = column;

            //Create text element to control the text flow
            PdfTextElement element = new PdfTextElement(text, font);
            element.Brush = new PdfSolidBrush(Color.Black);
            element.StringFormat = format;
            PdfLayoutSettings layoutFormat = new PdfLayoutSettings();
            layoutFormat.Break = PdfLayoutBreakType.FitPage;
            layoutFormat.Layout = PdfLayoutType.Paginate;

            //Get the remaining text that flows beyond the boundary.
            PdfTextLayoutResult result = element.Draw(page, _bounds, layoutFormat);

            expath = CommonDataPath + "\\OfficeComponentPdf.txt";
            reader = new StreamReader(expath, Encoding.ASCII);
            text = reader.ReadToEnd();
            reader.Close();

            element = new PdfTextElement(text, font);
            element.Brush = new PdfSolidBrush(Color.Black);
            element.StringFormat = format;

            // Next paragraph flow from last line of the previous paragraph.
            _bounds.Y = result.LastLineBounds.Y + 35f;

            //Raise the event when the text flows to next page.
            element.BeforePageLayout += BeginPageLayout2;

            //Raise the event when the text reaches the end of the page.
            element.AfterPageLayout += EndPageLayout2;
            result.Page.Graphics.DrawString("OfficeComponentPdf", heading, PdfBrushes.DarkBlue, new PointF(_bounds.X, _bounds.Y));

            _bounds.Y = result.LastLineBounds.Y + 60f;
            element.Draw(result.Page, new RectangleF(_bounds.X, _bounds.Y, _bounds.Width, -1), layoutFormat);

            if (!Directory.Exists(CommonDataPath))
                Directory.CreateDirectory(CommonDataPath);

            // Save and close the document.
            var outputPath = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + ".pdf");
            doc.Save(outputPath);
            doc.Close(true);

            return outputPath;
  • VB Version:
    ' Create a new instance of PdfDocument class.
            Dim doc As New PdfDocument()


            ' Set document's information.
            doc.DocumentInformation.Author = "OfficeComponent"
            doc.DocumentInformation.Producer = "OfficeComponent"
            doc.DocumentInformation.Creator = "OfficeComponent"
            doc.DocumentInformation.Title = Title

            'Add a page
            Dim page As PdfPage = doc.Pages.Add()

            'Create font
            Dim font As New PdfStandardFont(PdfFontFamily.Helvetica, 11.5F)

            Dim ttf As New Font("Calibri", 14F, FontStyle.Bold)
            Dim heading As New PdfTrueTypeFont(ttf, True)

            'Adding Header
            AddHeader(doc, "OfficeComponent OfficeComponentPdf", "Header and Footer Demo")

            'Adding Footer
            AddFooter(doc, "@Copyright " & Date.Now.Year)

            'Set formats
            Dim format As New PdfStringFormat()
            format.Alignment = PdfTextAlignment.Justify
            Dim expath As String = CommonDataPath & "\About.txt"
            Dim reader As New StreamReader(expath, Encoding.ASCII)
            Dim text As String = reader.ReadToEnd()
            reader.Close()

            Dim column As New RectangleF(0, 20, page.Graphics.ClientSize.Width - 10F, page.Graphics.ClientSize.Height)
            _bounds = column

            'Create text element to control the text flow
            Dim element As New PdfTextElement(text, font)
            element.Brush = New PdfSolidBrush(Color.Black)
            element.StringFormat = format
            Dim layoutFormat As New PdfLayoutSettings()
            layoutFormat.Break = PdfLayoutBreakType.FitPage
            layoutFormat.Layout = PdfLayoutType.Paginate

            'Get the remaining text that flows beyond the boundary.
            Dim result As PdfTextLayoutResult = element.Draw(page, _bounds, layoutFormat)

            expath = CommonDataPath & "\OfficeComponentPdf.txt"
            reader = New StreamReader(expath, Encoding.ASCII)
            text = reader.ReadToEnd()
            reader.Close()

            element = New PdfTextElement(text, font)
            element.Brush = New PdfSolidBrush(Color.Black)
            element.StringFormat = format

            ' Next paragraph flow from last line of the previous paragraph.
            _bounds.Y = result.LastLineBounds.Y + 35F

            'Raise the event when the text flows to the next page.
            AddHandler element.BeforePageLayout, AddressOf BeginPageLayout2

            'Raise the event when the text reaches the end of the page.
            AddHandler element.AfterPageLayout, AddressOf EndPageLayout2
            result.Page.Graphics.DrawString("OfficeComponentPdf", heading, PdfBrushes.DarkBlue, New PointF(_bounds.X, _bounds.Y))

            _bounds.Y = result.LastLineBounds.Y + 60F
            element.Draw(result.Page, New RectangleF(_bounds.X, _bounds.Y, _bounds.Width, -1), layoutFormat)

            If Not Directory.Exists(CommonDataPath) Then
                Directory.CreateDirectory(CommonDataPath)
            End If

            ' Save and close the document.
            Dim outputPath = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & ".pdf")
            doc.Save(outputPath)
            doc.Close(True)

            Return outputPath

The full source code of this example is available in our PDF package.

A live demo for PDF Header and Footer is also available on our site. If you also need PDF functionality, check out our PDF online demos.

45-Day Money Back Guarantee

We will refund your full money in 45 days
if you are not satisfied with our products

Buy Now
You have successfully subcribed to our mailing list.
Dont miss out Get update on new articles and other opportunities Subscribe