This quick tutorial explains how to remove header and footer from PDF in Java. It provides details to set the IDE using the given resources, a list of programming steps, and a runnable sample code to remove PDF header and footer in Java. You will learn different options to delete stamps using page number, stamp index, and stamp ID as per requirement.
Steps to Remove Header and Footer from PDF in Java
- Set the IDE to use Aspose.PDF for Java to remove headers
- Create the PdfContentEditor object
- Call the bindPdf() method for binding the target PDF file
- Call the deleteStamp() method by providing the page number and list of stamp indexes
- Save the PDF file after removing the header and footer
The above steps demonstrate the process to remove header and footer in PDF in Java. The process starts by creating an object of the PdfContentEditor class and binding it with the loaded PDF file to access and delete its desired contents. Call the deleteStamp() method by passing the source page number and an array of the indexes of the headers/footers to be deleted.
Code to Remove Header Footer from PDF in Java
This code shows how in a PDF remove header and footer in Java with the help of a few API calls only. The PdfContentEditor class has multiple methods to delete headers and footers such as deleteStamp(), deleteStampByIds(), and deleteStampById() that take different arguments to perform the task. You can also move the stamp in a PDF file using the moveStamp() method.
In this article, we have learned the PDF header footer removal in Java. If you want to remove pages from a PDF, refer to the article on how to remove pages from PDF using Java.