Top Fields Constructors Methods
org.apache.pdfbox.pdfparser

public Class PDFParser

extends COSParser
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.Loader, org.apache.pdfbox.cos.COSDictionary, .COSName, org.apache.pdfbox.io.IOUtils, .RandomAccessRead, .RandomAccessStreamCache.StreamCacheCreateFunction, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException

Field Summary

Modifier and TypeField and Description
private static final Log
Inherited from org.apache.pdfbox.pdfparser.COSParser:
EOF_MARKERfileLeninitialParseDoneOBJ_MARKERsecurityHandlerSYSPROP_EOFLOOKUPRANGExrefTrailerResolver

Constructor Summary

AccessConstructor and Description
public
PDFParser(RandomAccessRead
source representing the pdf.
source
)

Constructor.

public
PDFParser(RandomAccessRead
input representing the pdf.
source
,
String
password to be used for decryption.
decryptionPassword
)

Constructor.

public
PDFParser(RandomAccessRead
input representing the pdf.
source
,
String
password to be used for decryption.
decryptionPassword
,
InputStream
key store to be used for decryption when using public key security
keyStore
,
String
alias to be used for decryption when using public key security
alias
)

Constructor.

public
PDFParser(RandomAccessRead
input representing the pdf.
source
,
String
password to be used for decryption.
decryptionPassword
,
InputStream
key store to be used for decryption when using public key security
keyStore
,
String
alias to be used for decryption when using public key security
alias
,
RandomAccessStreamCache.StreamCacheCreateFunction
a function to create an instance of the stream cache
streamCacheCreateFunction
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected PDDocument

Returns:

the resulting document
createDocument
()

Create the resulting document.

protected void
initialParse()

The initial parse will first parse only the trailer, the xrefstart and all xref tables to have a pointer (offset) to all the pdf's objects.

public static PDDocument

Returns:

loaded document
load
(File
file to be loaded
file
)
Deprecated use Loader#loadPDF(File) instead

Parses a PDF.

public static PDDocument

Returns:

loaded document
load
(File
file to be loaded
file
,
String
password to be used for decryption
password
)
Deprecated use Loader#loadPDF(File, String) instead

Parses a PDF.

public PDDocument

Returns:

the populated PDDocument
parse
()

This will parse the stream and populate the PDDocument object.

public PDDocument

Returns:

the populated PDDocument
parse
(boolean
activate leniency if set to true
lenient
)

This will parse the stream and populate the PDDocument object.

Inherited from org.apache.pdfbox.pdfparser.COSParser:
checkPagescreateRandomAccessReadViewdereferenceCOSObjectgetAccessPermissiongetEncryptionisLenientisStringlastIndexOfparseCOSStreamparseFDFHeaderparseObjectDynamicallyparseObjectStreamObjectparsePDFHeaderparseXrefTableprepareDecryptionresetTrailerResolverretrieveTrailersetEOFLookupRangesetLenient

Field Detail

LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.pdfparser.COSParser.LOG.

Constructor Detail

PDFParserback to summary
public PDFParser(RandomAccessRead source) throws IOException

Constructor. Unrestricted main memory will be used for buffering PDF streams.

Parameters
source:RandomAccessRead

source representing the pdf.

Exceptions
IOException:
If something went wrong.
PDFParserback to summary
public PDFParser(RandomAccessRead source, String decryptionPassword) throws IOException

Constructor. Unrestricted main memory will be used for buffering PDF streams.

Parameters
source:RandomAccessRead

input representing the pdf.

decryptionPassword:String

password to be used for decryption.

Exceptions
IOException:
If something went wrong.
PDFParserback to summary
public PDFParser(RandomAccessRead source, String decryptionPassword, InputStream keyStore, String alias) throws IOException

Constructor. Unrestricted main memory will be used for buffering PDF streams.

Parameters
source:RandomAccessRead

input representing the pdf.

decryptionPassword:String

password to be used for decryption.

keyStore:InputStream

key store to be used for decryption when using public key security

alias:String

alias to be used for decryption when using public key security

Exceptions
IOException:
If something went wrong.
PDFParserback to summary
public PDFParser(RandomAccessRead source, String decryptionPassword, InputStream keyStore, String alias, RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction) throws IOException

Constructor.

Parameters
source:RandomAccessRead

input representing the pdf.

decryptionPassword:String

password to be used for decryption.

keyStore:InputStream

key store to be used for decryption when using public key security

alias:String

alias to be used for decryption when using public key security

streamCacheCreateFunction:RandomAccessStreamCache.StreamCacheCreateFunction

a function to create an instance of the stream cache

Exceptions
IOException:
If something went wrong.

Method Detail

createDocumentback to summary
protected PDDocument createDocument() throws IOException

Create the resulting document. Maybe overwritten if the parser uses another class as document.

Returns:PDDocument

the resulting document

Exceptions
IOException:
if the method is called before parsing the document
initialParseback to summary
protected void initialParse() throws IOException

The initial parse will first parse only the trailer, the xrefstart and all xref tables to have a pointer (offset) to all the pdf's objects. It can handle linearized pdfs, which will have an xref at the end pointing to an xref at the beginning of the file. Last the root object is parsed.

Exceptions
IOException:
If something went wrong.
InvalidPasswordException:
If the password is incorrect.
loadback to summary
public static PDDocument load(File file) throws IOException

Deprecated

use Loader#loadPDF(File) instead

Parses a PDF. Unrestricted main memory will be used for buffering PDF streams.

Parameters
file:File

file to be loaded

Returns:PDDocument

loaded document

Annotations
@Deprecated
Exceptions
IOException:
in case of a file reading or parsing error
InvalidPasswordException:
If the file required a non-empty password.
loadback to summary
public static PDDocument load(File file, String password) throws IOException

Deprecated

use Loader#loadPDF(File, String) instead

Parses a PDF. Unrestricted main memory will be used for buffering PDF streams.

Parameters
file:File

file to be loaded

password:String

password to be used for decryption

Returns:PDDocument

loaded document

Annotations
@Deprecated
Exceptions
IOException:
in case of a file reading or parsing error
InvalidPasswordException:
If the password is incorrect.
parseback to summary
public PDDocument parse() throws IOException

This will parse the stream and populate the PDDocument object. This will close the keystore stream when it is done parsing. Lenient mode is active by default.

Returns:PDDocument

the populated PDDocument

Exceptions
IOException:
If there is an error reading from the stream or corrupt data is found.
InvalidPasswordException:
If the password is incorrect.
parseback to summary
public PDDocument parse(boolean lenient) throws IOException

This will parse the stream and populate the PDDocument object. This will close the keystore stream when it is done parsing.

Parameters
lenient:boolean

activate leniency if set to true

Returns:PDDocument

the populated PDDocument

Exceptions
IOException:
If there is an error reading from the stream or corrupt data is found.
InvalidPasswordException:
If the password is incorrect.