public class PdfReader extends Object implements PdfViewerPreferences
| Modifier and Type | Field and Description |
|---|---|
protected PdfDictionary |
catalog |
protected PRTokeniser |
tokens |
protected PdfDictionary |
trailer |
| Modifier | Constructor and Description |
|---|---|
protected |
PdfReader() |
|
PdfReader(byte[] pdfIn)
Reads and parses a PDF document.
|
|
PdfReader(byte[] pdfIn,
byte[] ownerPassword)
Reads and parses a PDF document.
|
|
PdfReader(InputStream is)
Reads and parses a PDF document.
|
|
PdfReader(String filename)
Reads and parses a PDF document.
|
|
PdfReader(String filename,
Certificate certificate,
Key certificateKey,
String certificateKeyProvider)
Reads and parses a PDF document.
|
| Modifier and Type | Method and Description |
|---|---|
PRIndirectReference |
addPdfObject(PdfObject obj) |
void |
addViewerPreference(PdfName key,
PdfObject value)
Adds a viewer preference
|
void |
close()
Closes the reader
|
static byte[] |
FlateDecode(byte[] in,
boolean strict)
A helper to FlateDecode.
|
AcroFields |
getAcroFields()
Gets a read-only version of
AcroFields. |
com.aowagie.text.pdf.PRAcroForm |
getAcroForm()
Returns the document's acroform, if it has one.
|
PdfDictionary |
getCatalog()
Returns the document's catalog.
|
int |
getCertificationLevel()
Gets the certification level for this document.
|
int |
getCryptoMode() |
int |
getEofPos()
Gets the byte address of the %%EOF marker.
|
int |
getFileLength()
Getter for property fileLength.
|
HashMap |
getInfo()
Returns the content of the document information dictionary as a
HashMap
of String. |
String |
getJavaScript()
Gets the global document JavaScript.
|
int |
getLastXref()
Gets the byte address of the last xref table.
|
byte[] |
getMetadata()
Gets the XML metadata.
|
HashMap |
getNamedDestination()
Gets all the named destinations as an
HashMap. |
HashMap |
getNamedDestinationFromNames()
Gets the named destinations from the /Dests key in the catalog as an
HashMap. |
HashMap |
getNamedDestinationFromStrings()
Gets the named destinations from the /Names key in the catalog as an
HashMap. |
int |
getNumberOfPages()
Gets the number of pages in the document.
|
byte[] |
getPageContent(int pageNum,
RandomAccessFileOrArray file)
Gets the contents of the page.
|
PdfDictionary |
getPageN(int pageNum)
Gets the dictionary that represents a page.
|
PdfDictionary |
getPageNRelease(int pageNum) |
PRIndirectReference |
getPageOrigRef(int pageNum)
Gets the page reference to this page.
|
Rectangle |
getPageSize(int index)
Gets the page size without taking rotation into account.
|
Rectangle |
getPageSizeWithRotation(int index)
Gets the page size, taking rotation into account.
|
PdfObject |
getPdfObject(int idx) |
static PdfObject |
getPdfObject(PdfObject obj)
Reads a
PdfObject resolving an indirect reference
if needed. |
static PdfObject |
getPdfObjectRelease(PdfObject obj) |
protected com.aowagie.text.pdf.PdfReaderInstance |
getPdfReaderInstance(PdfWriter writer) |
char |
getPdfVersion()
Gets the PDF version.
|
int |
getPermissions()
Gets the encryption permissions.
|
RandomAccessFileOrArray |
getSafeFile()
Gets a new file instance of the original PDF
document.
|
int |
getSimpleViewerPreferences()
Returns a bitset representing the PageMode and PageLayout viewer preferences.
|
static byte[] |
getStreamBytes(PRStream stream)
Get the content from a stream applying the required filters.
|
PdfDictionary |
getTrailer()
Gets the trailer dictionary
|
int |
getXrefSize()
Gets the number of xref objects.
|
boolean |
isAppendable()
Getter for property appendable.
|
boolean |
isEncrypted()
Returns
true if the PDF is encrypted. |
boolean |
isHybridXref()
Getter for property hybridXref.
|
boolean |
isMetadataEncrypted() |
boolean |
isNewXrefType()
Getter for property newXrefType.
|
boolean |
isOpenedWithFullPermissions()
Checks if the document was opened with the owner password so that the end application
can decide what level of access restrictions to apply.
|
boolean |
isRebuilt()
Checks if the document had errors and was rebuilt.
|
boolean |
isTampered()
Checks if the document was changed.
|
protected void |
killXref(PdfObject obj) |
protected void |
readDocObj() |
protected void |
readPages() |
protected void |
readPdf() |
protected void |
rebuildXref() |
void |
releasePage(int pageNum) |
void |
removeUsageRights()
Removes any usage rights that this PDF may have.
|
void |
resetReleasePage() |
void |
setAppendable(boolean appendable)
Setter for property appendable.
|
void |
setTampered(boolean tampered)
Sets the tampered state.
|
void |
setViewerPreferences(int preferences)
Sets the viewer preferences as the sum of several constants.
|
protected PRTokeniser tokens
protected PdfDictionary trailer
protected PdfDictionary catalog
protected PdfReader()
public PdfReader(String filename) throws IOException
filename - the file name of the documentIOException - on errorpublic PdfReader(byte[] pdfIn)
throws IOException
pdfIn - the byte array with the documentIOException - on errorpublic PdfReader(byte[] pdfIn,
byte[] ownerPassword)
throws IOException
pdfIn - the byte array with the documentownerPassword - the password to read the documentIOException - on errorpublic PdfReader(String filename, Certificate certificate, Key certificateKey, String certificateKeyProvider) throws IOException
filename - the file name of the documentcertificate - the certificate to read the documentcertificateKey - the private key of the certificatecertificateKeyProvider - the security provider for certificateKeyIOException - on errorpublic PdfReader(InputStream is) throws IOException
is - the InputStream containing the document. The stream is read to the
end but is not closedIOException - on errorpublic RandomAccessFileOrArray getSafeFile()
protected com.aowagie.text.pdf.PdfReaderInstance getPdfReaderInstance(PdfWriter writer)
public int getNumberOfPages()
public PdfDictionary getCatalog()
public com.aowagie.text.pdf.PRAcroForm getAcroForm()
public Rectangle getPageSizeWithRotation(int index)
Rectangle with the value of the /MediaBox and the /Rotate key.index - the page number. The first page is 1Rectangle.public Rectangle getPageSize(int index)
index - the page number. The first page is 1public HashMap getInfo()
HashMap
of String.protected void readPdf()
throws IOException
IOExceptionpublic static PdfObject getPdfObjectRelease(PdfObject obj)
obj - object to releasepublic static PdfObject getPdfObject(PdfObject obj)
PdfObject resolving an indirect reference
if needed.obj - the PdfObject to readPdfObjectpublic PdfObject getPdfObject(int idx)
idx - index to getpublic PRIndirectReference addPdfObject(PdfObject obj)
obj - object to addprotected void readPages()
throws IOException
IOExceptionprotected void readDocObj()
throws IOException
IOExceptionprotected void rebuildXref()
throws IOException
IOExceptionpublic static byte[] FlateDecode(byte[] in,
boolean strict)
in - the input datastrict - true to read a correct stream. false
to try to read a corrupted streampublic boolean isRebuilt()
public PdfDictionary getPageN(int pageNum)
pageNum - the page number. 1 is the firstpublic PdfDictionary getPageNRelease(int pageNum)
pageNum - number of pagepublic void releasePage(int pageNum)
pageNum - number of pagepublic void resetReleasePage()
public PRIndirectReference getPageOrigRef(int pageNum)
pageNum - the page number. 1 is the firstpublic byte[] getPageContent(int pageNum,
RandomAccessFileOrArray file)
throws IOException
pageNum - the page number. 1 is the firstfile - the location of the PDF documentIOException - on errorprotected void killXref(PdfObject obj)
public static byte[] getStreamBytes(PRStream stream) throws IOException
stream - the streamIOException - on errorpublic boolean isTampered()
true if the document was changed,
false otherwisepublic void setTampered(boolean tampered)
tampered - the tampered statepublic byte[] getMetadata()
throws IOException
IOException - on errorpublic int getLastXref()
public int getXrefSize()
public int getEofPos()
public char getPdfVersion()
public boolean isEncrypted()
true if the PDF is encrypted.true if the PDF is encryptedpublic int getPermissions()
PdfWriter.setEncryption().public PdfDictionary getTrailer()
public HashMap getNamedDestination()
HashMap. The key is the name
and the value is the destinations array.public HashMap getNamedDestinationFromNames()
HashMap. The key is the name
and the value is the destinations array.public HashMap getNamedDestinationFromStrings()
HashMap. The key is the name
and the value is the destinations array.public void close()
public AcroFields getAcroFields()
AcroFields.AcroFieldspublic String getJavaScript() throws IOException
IOException - on errorpublic void setViewerPreferences(int preferences)
setViewerPreferences in interface PdfViewerPreferencespreferences - the viewer preferencesPdfViewerPreferences.setViewerPreferences(int)public void addViewerPreference(PdfName key, PdfObject value)
addViewerPreference in interface PdfViewerPreferenceskey - a key for a viewer preferencevalue - a value for the viewer preferencePdfViewerPreferences.addViewerPreference(com.aowagie.text.pdf.PdfName, com.aowagie.text.pdf.PdfObject)public int getSimpleViewerPreferences()
public boolean isAppendable()
public void setAppendable(boolean appendable)
appendable - New value of property appendable.public boolean isNewXrefType()
public int getFileLength()
public boolean isHybridXref()
public void removeUsageRights()
public int getCertificationLevel()
PdfSignatureAppearance.NOT_CERTIFIED,
PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED,
PdfSignatureAppearance.CERTIFIED_FORM_FILLING and
PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS.
No signature validation is made, use the methods available for that in AcroFields.
public final boolean isOpenedWithFullPermissions()
true.true if the document was opened with the owner password or if it's not encrypted,
false if the document was opened with the user passwordpublic int getCryptoMode()
public boolean isMetadataEncrypted()
Copyright © 2021. All rights reserved.