Top Description Fields Constructors Methods
org.apache.pdfbox.multipdf

public Class PageExtractor

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.List, org.apache.pdfbox.pdmodel.PDDocument

This class will extract one or more sequential pages and create a new document.
Author
Adam Nichols ([email protected])

Field Summary

Modifier and TypeField and Description
private int
private final PDDocument
private int

Constructor Summary

AccessConstructor and Description
public
PageExtractor(PDDocument
The document to split.
sourceDocument
)

Creates a new instance of PageExtractor

public
PageExtractor(PDDocument
The document to split.
sourceDocument
,
int
The first page you want extracted (1-based, inclusive)
startPage
,
int
The last page you want extracted (1-based, inclusive)
endPage
)

Creates a new instance of PageExtractor

Method Summary

Modifier and TypeMethod and Description
public PDDocument

Returns:

The extracted document
extract
()

This will take a document and extract the desired pages into a new document.

public int

Returns:

the last page number which should be extracted
getEndPage
()

Gets the last page number (inclusive) to be extracted.

public int

Returns:

the first page number which should be extracted
getStartPage
()

Gets the first page number to be extracted.

public void
setEndPage(int
the last page number which should be extracted
endPage
)

Sets the last page number to be extracted.

public void
setStartPage(int
the first page number which should be extracted
startPage
)

Sets the first page number to be extracted.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

endPageback to summary
private int endPage
sourceDocumentback to summary
private final PDDocument sourceDocument
startPageback to summary
private int startPage

Constructor Detail

PageExtractorback to summary
public PageExtractor(PDDocument sourceDocument)

Creates a new instance of PageExtractor

Parameters
sourceDocument:PDDocument

The document to split.

PageExtractorback to summary
public PageExtractor(PDDocument sourceDocument, int startPage, int endPage)

Creates a new instance of PageExtractor

Parameters
sourceDocument:PDDocument

The document to split.

startPage:int

The first page you want extracted (1-based, inclusive)

endPage:int

The last page you want extracted (1-based, inclusive)

Method Detail

extractback to summary
public PDDocument extract() throws IOException

This will take a document and extract the desired pages into a new document. Both startPage and endPage are included in the extracted document. If the endPage is greater than the number of pages in the source document, it will go to the end of the document. If startPage is less than 1, it'll start with page 1. If startPage is greater than endPage or greater than the number of pages in the source document, a blank document will be returned.

Returns:PDDocument

The extracted document

Exceptions
IOException:
If there is an IOError
getEndPageback to summary
public int getEndPage()

Gets the last page number (inclusive) to be extracted.

Returns:int

the last page number which should be extracted

getStartPageback to summary
public int getStartPage()

Gets the first page number to be extracted.

Returns:int

the first page number which should be extracted

setEndPageback to summary
public void setEndPage(int endPage)

Sets the last page number to be extracted.

Parameters
endPage:int

the last page number which should be extracted

setStartPageback to summary
public void setStartPage(int startPage)

Sets the first page number to be extracted.

Parameters
startPage:int

the first page number which should be extracted