Discover how to remove headers and footers from a PDF using C# in this concise, step‑by‑step guide. We’ll walk you through setting up the development environment with the NuGet package manager, then show you how to build the application from scratch. Included is ready‑to‑run sample code that eliminates headers and footers from a PDF using C#, offering flexible options to delete them individually or in bulk—exactly what you need for any PDF processing task.
Steps to Remove Header and Footer in PDF using C#
- Use the NuGet package manager to add Conholdate.Total for .NET to remove headers and footers
- Create an instance of the PdfContentEditor to edit the PDF
- Link the target PDF file with the PdfContentEditor object using the BindPdf() method
- Using the PdfContentEditor object, call the DeleteStamp() method
- Save the resultant PDF file after removing the header or footer from it
This guide outlines the procedure to *remove headers and footers from a PDF using C#. The PdfContentEditor is created and linked to the target PDF file. Subsequently, the DeleteStamp() method is employed, which requires the page index (beginning from 1) and an array of integers specifying the indexes of the stamps (headers and footers) to be eliminated from the page. The PdfContentEditor also features a save() method, enabling the saving of the modified PDF file to either the disk or a stream.
Code to Remove Header and Footer from PDF using C#
With the sample code in hand you now have a straightforward way to strip headers and footers from any PDF using C#. Call DeleteStamp(pageNumber, stampIndex), where pageNumber specifies the target page and stampIndex is the 0‑based index that identifies the header or footer to delete. If you prefer to work with the stamp’s identifier, use DeleteStampById(pageNumber, stampId), providing the page number and the unique ID assigned to the stamp when it was created.
Now you’ve mastered removing headers and footers from a PDF with C#. When you’re ready to put them back, explore our step‑by‑step tutorial on how to add header and footer in PDF using C#.