Extract Pages from a PDF Document

Skip to end of metadata
Go to start of metadata
Extract Pages from a PDF Document

Developers can extract any page or pages from a PDF document and save those pages as a new PDF document. This is acheived by simply calling Extract method of PdfFileEditor class.

Extract method takes three arguments. First is the input stream (holding the PDF document, inStream) from which the pages will be extracted. Second argument is the Array of integers containing the page numbers of the pages to be extracted from inStream. Third parameter is the output stream (outputStream) that would contain the extracted pages from the inStream as a PDF document.

[Java]
//Initialize the string variables storing paths of PDF files
String inFile = "example1.pdf";
String outFile = "kitOut.pdf";

//Creating an array of integers having numbers of the pages to be extracted from PDF file
int[] pages = new int[] { 1, 2, 4, 10, 100 };

PdfFileEditor pdfEditor = new PdfFileEditor();

//Calling Extract method
pdfEditor.extract(inFile, pages, outFile);
 

Other overloaded methods of Extract also offer developers to extract a specified range of pages from a PDF document and get those extracted pages as a separate PDF file.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.