How to Remove Header and Footer from PDF using C#

This short tutorial guides on how to remove header and footer from PDF using C#. It has the details to set the development environment using the NuGet package manager, a list of steps to develop the application, and a ready-to-run sample code to remove header footer from PDF using C#. You will learn different options to delete headers and footers individually or multiple as per requirements.

  1. Use the NuGet package manager to add Aspose.PDF for .NET to remove headers and footers
  2. Create an instance of the PdfContentEditor to edit the PDF
  3. Link the target PDF file with the PdfContentEditor object using the BindPdf() method
  4. Using the PdfContentEditor object, call the DeleteStamp() method
  5. Save the resultant PDF file after removing the header or footer from it

These steps define the process of how in a PDF remove header and footer using C#. The PdfContentEditor is instantiated and bound with the target PDF file and then the DeleteStamp() method is used that take the page index starting from 1 and an array of integers containing the indexes of the stamps (headers and footers) to be removed from the page. The PdfContentEditor contains the save() method that can save the loaded PDF file on the disk or stream.

This code demonstrates the process to remove PDF header and footer using C#. The DeleteStamp method takes two arguments where the first index is page number and the second argument is 0 based index of stamp that can be either a header or footer. Another option to delete the header or footer is to use DeleteStampById() by providing the page number followed by the unique ID of the stamp assigned at the time of creation.

This article has taught us to delete header and footer in PDF using C#. If you want to learn the process to add header and footer in a PDF file, refer to the article on how to add header and footer in PDF using C#.