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 (JAVA Version) method of PdfFileEditor (JAVA Version) class.
Extract (JAVA Version) 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.
Code Snippet
[C#]
//Initialize the string variables storing paths of PDF files
string inFile = ".\\example1.pdf";
string outFile = ".\\ExtractStream.pdf";
//Creating stream objects holding the PDF files in Open Mode
FileStream inStream = new FileStream(inFile,FileMode.Open);
//Creating output stream object that will store the extracted pages as a PDF file
FileStream outputStream = new FileStream(outFile,FileMode.Create);
//Instantiating PdfFileEditor object
PdfFileEditor editor = new PdfFileEditor();
//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};
//Calling Extract method
editor.Extract(inStream,pages,outputStream);
//Closing output stream
outputStream.Close();
[VB.NET]
'Initialize the string variables storing paths of PDF files
Dim inFile As String = ".\\example1.pdf"
Dim outFile As String = ".\\ExtractStream.pdf"
'Creating stream objects holding the PDF files in Open Mode
Dim inStream As FileStream = New FileStream(inFile,FileMode.Open)
'Creating output stream object that will store the extracted pages as a PDF file
Dim outputStream As FileStream = New FileStream(outFile,FileMode.Create)
'Instantiating PdfFileEditor object
Dim editor As PdfFileEditor = New PdfFileEditor()
'Creating an array of integers having numbers of the pages to be extracted from PDF file
Dim pages() As Integer = New Integer() {1,2,4,10,100}
'Calling Extract method
editor.Extract(inStream,pages,outputStream)
'Closing output stream
outputStream.Close()
[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 (JAVA Version ) also offer developers to extract a specified range of pages from a PDF document and get those extracted pages as a separate PDF file.