public final class PDFReader extends Object
The PDFReader
class adds the ability to load an existing PDF to the
library. Note that this class is part of the "Extended Edition" of the
library - although it's supplied with the package an "extended edition"
license must be purchased to activate this class.
There are a number of constructors on this class which can be used to load a PDF
from File
and InputStream
objects, but - while valid - these are all
now wrappers on a more generalized approach. These methods will not be deprecated
and existing code has no need to change, but for more flexiblity the new approach is recommended:
PDFReader reader = new PDFReader(); reader.setSource(source); reader.addEncryptionHandler(handler); // optional reader.load(); PDF pdf = new PDF(reader);
A PDF file may sometimes contain different versions of itself in the one file. These "revisions" show how the state of the document has changed over time. For most purposes this information isn't terribly useful - prior to version 1.2.1 only the latest revision was used - but they do play an important role when using Digital Signatures.
When a signature is applied to the file, the current revision is locked and any further changes to the file result in a new revision being made. With Adobe Acrobat several signatures can be applied, each one of which will result in a new revision.
It's important to remember that changes can be made a document after it's been signed, and provided that they're made in a new revision, the signature won't be invalidated - but the signature won't cover the whole of the document either. When validating a signed document this needs to be taken into account
Another interesting feature of revisions is that with a document with multiple
revisions, it's possible to "roll back" to a previous version. This is done by
passing in a specific revision number to the PDF.PDF(PDFReader,int)
constructor - the PDF will be created as it was at the specified revision.
Parallel Operation note: Since 2.10 this class
will use multiple threads in parallel where possible. The number of threads
defaults to the available processors
but can
be controlled by setting the Threads
property
(typically by setting the
org.faceless.pdf2.Threads
System property
)
to the number of threads required. Each thread requires only minimal heap so it's
safe to run as many as you like.
Constructor and Description |
---|
PDFReader()
Create a new PDFReader.
|
PDFReader(File in)
Read an unencrypted PDF from the specified file.
|
PDFReader(File in,
EncryptionHandler encrypt)
Read an encrypted PDF from the specified File.
|
PDFReader(File in,
EncryptionHandler[] encryptlist,
float[] progress)
Read a PDF from the specified File, and report on progress.
|
PDFReader(File in,
EncryptionHandler encrypt,
float[] progress)
Read a PDF from the specified InputStream, and report on progress.
|
PDFReader(File in,
String password)
Read an encrypted PDF from the specified File.
|
PDFReader(InputStream in)
Read an encrypted PDF from the specified InputStream.
|
PDFReader(InputStream in,
EncryptionHandler encrypt)
Read an encrypted PDF from the specified InputStream.
|
PDFReader(InputStream in,
EncryptionHandler[] encryptlist,
float[] progress)
Read a PDF from the specified InputStream, and report on progress.
|
PDFReader(InputStream in,
EncryptionHandler encrypt,
float[] progress)
Read a PDF from the specified InputStream, and report on progress.
|
PDFReader(InputStream in,
String password)
Read an encrypted PDF from the specified InputStream.
|
Modifier and Type | Method and Description |
---|---|
void |
addEncryptionHandler(EncryptionHandler handler)
Add an
EncryptionHandler to be tried when loading the PDF. |
int |
getNumberOfRevisions()
Return the number of revisions that have been made to this file.
|
float |
getProgress()
Return the progress of the load, from 0 to 1
|
void |
load()
Load the PDF from the specified source (set by
setSource(java.io.File) , which must be
called before this method). |
void |
setLinearizedLoader(boolean linearizer)
Set whether to use the Linearization tables (if they exist) in the PDF to
load it on demand.
|
void |
setSource(File file)
Set the source for this PDFReader to the specified File.
|
void |
setSource(InputStream in)
Set the source for this PDFReader to the specified InputStream.
|
void |
setSource(URL url)
Set the source for this PDFReader to the specified URL.
|
public PDFReader()
setSource(java.io.File)
method and then the load()
method
must be called before this object is passed into the PDF.PDF(PDFReader)
constructor.public PDFReader(File in) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.load();
in
- the File to read fromIOException
public PDFReader(File in, String password) throws IOException
StandardEncryptionHandler
and the specified password.
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(new StandardEncryptionHandler(password)); reader.load();
in
- the File to read frompassword
- the password needed to open the file, or null
for no passwordIOException
public PDFReader(InputStream in) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.load();
in
- the InputStream to read fromIOException
public PDFReader(InputStream in, String password) throws IOException
StandardEncryptionHandler
and the specified password.
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(new StandardEncryptionHandler(password)); reader.load();
in
- the InputStream to read frompassword
- the password needed to open the file, or null
for no passwordIOException
public PDFReader(InputStream in, EncryptionHandler encrypt) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(encrypt); reader.load();
in
- the InputStream to read fromencrypt
- the EncryptionHandler to decrypt the PDF, or null
for no encryptionIOException
public PDFReader(File in, EncryptionHandler encrypt) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(encrypt); reader.load();
in
- the InputStream to read fromencrypt
- the EncryptionHandler to decrypt the PDF, or null
for no encryptionIOException
public PDFReader(InputStream in, EncryptionHandler encrypt, float[] progress) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(encrypt); reader.load();
in
- the stream to read fromencrypt
- the EncryptionHandler to decrypt the PDF, or null
for no encryptionprogress
- an optional array one item long, the first parameter of which will by updated throughout the readIOException
public PDFReader(File in, EncryptionHandler encrypt, float[] progress) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(encrypt); reader.load();
in
- the File to read fromencrypt
- the EncryptionHandler to decrypt the PDF, or null
for no encryptionprogress
- an optional array one item long, the first parameter of which will by updated throughout the readIOException
public PDFReader(InputStream in, EncryptionHandler[] encryptlist, float[] progress) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(...encryptlist entries...); reader.load();
in
- the InputStream to read fromencryptlist
- the list of possible EncryptionHandlers to decrypt the PDF, or null
for no encryptionprogress
- an optional array one item long, the first parameter of which will by updated throughout the readIOException
public PDFReader(File in, EncryptionHandler[] encryptlist, float[] progress) throws IOException
This legacy constructor is equivalent to the following code - see the API documentation for those methods for details:
PDFReader reader = new PDFReader(); reader.setSource(in); reader.addEncryptionHandler(...encryptlist entries...); reader.load();
in
- the File to read fromencryptlist
- the list of possible EncryptionHandlers to decrypt the PDF, or null
for no encryptionprogress
- an optional array one item long, the first parameter of which will by updated throughout the readIOException
public void setSource(File file) throws IOException
PDF
created from this PDFReader.IOException
setSource(URL)
,
setSource(InputStream)
public void setSource(InputStream in) throws IOException
IOException
setSource(File)
,
setSource(URL)
public void setSource(URL url) throws IOException
PDF
created from this PDFReader.IOException
setSource(File)
,
setSource(InputStream)
,
setLinearizedLoader(boolean)
public void setLinearizedLoader(boolean linearizer)
URL
, false otherwise.setSource(URL)
public void addEncryptionHandler(EncryptionHandler handler)
EncryptionHandler
to be tried when loading the PDF.
Any items added here will be tried in order until one succeeds.public float getProgress()
public void load() throws IOException
setSource(java.io.File)
, which must be
called before this method). The load
method should be called before
the PDFReader
is passed to the PDF
constructor
- if it hasn't it will be called automatically at that point, but as the PDF constructor
does not throw an IOException
(for historical reasons), if one is thrown at that
point it will be wrapped in an IllegalStateException
.IOException
public int getNumberOfRevisions()
Return the number of revisions that have been made to this file.
Earlier revisions of a PDF file can be loaded by passing a revision
number less than this value to the appropriate PDF.PDF(PDFReader,int)
constructor.
Copyright © 2001-2017 Big Faceless Organization