This quick tutorial guides on how to save selected pages from PDF using Java. It enlists the configuration details for the IDE, a set of tasks to be performed while developing the application, and contains a runnable sample code demonstrating how to select pages from a PDF and save using Java. This code can be altered to change the extraction process and can be executed in any of the operating systems supporting the Java platform.
Steps to Save Selected Pages of PDF using Java
- Set the development environment to add Aspose.PDF for Java to extract pages
- Create a list of pages that are to be selected and saved
- Create an object of PdfFileEditor for saving selected pages in a separate PDF file
- Call the extract() method to save the selected pages
The process on how to select and save certain pages of a PDF using Java is summarized here. The process begins by providing a list of pages to be extracted from an existing PDF file followed by the initiation of the PdfFileEditor class object that supports extracting pages from a PDF. In the final step, the extract() method is used which requires input and output PDF file names along with the list of pages to be fetched.
Code to Save only Selected Pages from PDF using Java
The sample code demonstrating how to save selected PDF pages using Java is presented here. The PdfFileEditor class has a long list of features to work with PDF files for instance, setting the password, performing different types of conversions, concatenating the multiple PDF files, appending PDF files to an existing PDF file, and inserting pages at a particular index to name a few. You may extract either random PDF pages or a continuous range of pages as per the application requirements.
This article has taught us how to save selected pages in PDF using Java. If you want to learn the process to split the pages of a PDF, refer to the article on how to split PDF by pages in Java.