Class PdfReader
java.lang.Object
com.aowagie.text.pdf.PdfReader
- All Implemented Interfaces:
PdfViewerPreferences
Reads a PDF document.
- Author:
- Paulo Soares (psoares@consiste.pt), Kazuya Ujihara
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PdfDictionaryprotected PRTokeniserprotected PdfDictionary -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPdfReader(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.Reads and parses a PDF document.PdfReader(String filename, Certificate certificate, Key certificateKey, String certificateKeyProvider) Reads and parses a PDF document. -
Method Summary
Modifier and TypeMethodDescriptionaddPdfObject(PdfObject obj) voidaddViewerPreference(PdfName key, PdfObject value) Adds a viewer preferencevoidclose()Closes the readerstatic byte[]FlateDecode(byte[] in, boolean strict) A helper to FlateDecode.Gets a read-only version ofAcroFields.Returns the document's acroform, if it has one.Returns the document's catalog.intGets the certification level for this document.intintGets the byte address of the %%EOF marker.intGetter for property fileLength.getInfo()Returns the content of the document information dictionary as aHashMapofString.Gets the global document JavaScript.intGets the byte address of the last xref table.byte[]Gets the XML metadata.Gets all the named destinations as anHashMap.Gets the named destinations from the /Dests key in the catalog as anHashMap.Gets the named destinations from the /Names key in the catalog as anHashMap.intGets the number of pages in the document.byte[]getPageContent(int pageNum, RandomAccessFileOrArray file) Gets the contents of the page.getPageN(int pageNum) Gets the dictionary that represents a page.getPageNRelease(int pageNum) getPageOrigRef(int pageNum) Gets the page reference to this page.intgetPageRotation(int index) Gets the page rotation.intgetPageRotation(PdfDictionary page) getPageSize(int index) Gets the page size without taking rotation into account.getPageSizeWithRotation(int index) Gets the page size, taking rotation into account.getPdfObject(int idx) static PdfObjectgetPdfObject(PdfObject obj) Reads aPdfObjectresolving an indirect reference if needed.static PdfObjectprotected com.aowagie.text.pdf.PdfReaderInstancegetPdfReaderInstance(PdfWriter writer) charGets the PDF version.intGets the encryption permissions.Gets a new file instance of the original PDF document.intReturns a bitset representing the PageMode and PageLayout viewer preferences.static byte[]getStreamBytes(PRStream stream) Get the content from a stream applying the required filters.Gets the trailer dictionaryintGets the number of xref objects.booleanGetter for property appendable.booleanReturnstrueif the PDF is encrypted.booleanGetter for property hybridXref.booleanbooleanGetter for property newXrefType.final booleanChecks if the document was opened with the owner password so that the end application can decide what level of access restrictions to apply.booleanChecks if the document had errors and was rebuilt.booleanChecks if the document was changed.protected voidprotected voidprotected voidprotected voidreadPdf()protected voidvoidreleasePage(int pageNum) voidRemoves any usage rights that this PDF may have.voidvoidsetAppendable(boolean appendable) Setter for property appendable.voidsetTampered(boolean tampered) Sets the tampered state.voidsetViewerPreferences(int preferences) Sets the viewer preferences as the sum of several constants.
-
Field Details
-
tokens
-
trailer
-
catalog
-
-
Constructor Details
-
PdfReader
protected PdfReader() -
PdfReader
Reads and parses a PDF document.- Parameters:
filename- the file name of the document- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
pdfIn- the byte array with the document- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
pdfIn- the byte array with the documentownerPassword- the password to read the document- Throws:
IOException- on error
-
PdfReader
public PdfReader(String filename, Certificate certificate, Key certificateKey, String certificateKeyProvider) throws IOException Reads and parses a PDF document.- Parameters:
filename- the file name of the documentcertificate- the certificate to read the documentcertificateKey- the private key of the certificatecertificateKeyProvider- the security provider for certificateKey- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
is- theInputStreamcontaining the document. The stream is read to the end but is not closed- Throws:
IOException- on error
-
-
Method Details
-
getSafeFile
Gets a new file instance of the original PDF document.- Returns:
- a new file instance of the original PDF document
-
getPdfReaderInstance
-
getNumberOfPages
public int getNumberOfPages()Gets the number of pages in the document.- Returns:
- the number of pages in the document
-
getCatalog
Returns the document's catalog. This dictionary is not a copy, any changes will be reflected in the catalog.- Returns:
- the document's catalog
-
getAcroForm
Returns the document's acroform, if it has one.- Returns:
- the document's acroform
-
getPageRotation
public int getPageRotation(int index) Gets the page rotation. This value can be 0, 90, 180 or 270.- Parameters:
index- the page number. The first page is 1- Returns:
- the page rotation
-
getPageRotation
-
getPageSizeWithRotation
Gets the page size, taking rotation into account. This is aRectanglewith the value of the /MediaBox and the /Rotate key.- Parameters:
index- the page number. The first page is 1- Returns:
- a
Rectangle.
-
getPageSize
Gets the page size without taking rotation into account. This is the value of the /MediaBox key.- Parameters:
index- the page number. The first page is 1- Returns:
- the page size
-
getInfo
Returns the content of the document information dictionary as aHashMapofString.- Returns:
- content of the document information dictionary
-
readPdf
- Throws:
IOException
-
getPdfObjectRelease
-
getPdfObject
-
getPdfObject
- Parameters:
idx- index to get- Returns:
- aPdfObject returns a PdfObject
-
addPdfObject
- Parameters:
obj- object to add- Returns:
- an indirect reference
-
readPages
- Throws:
IOException
-
readDocObj
- Throws:
IOException
-
rebuildXref
- Throws:
IOException
-
FlateDecode
public static byte[] FlateDecode(byte[] in, boolean strict) A helper to FlateDecode.- Parameters:
in- the input datastrict-trueto read a correct stream.falseto try to read a corrupted stream- Returns:
- the decoded data
-
isRebuilt
public boolean isRebuilt()Checks if the document had errors and was rebuilt.- Returns:
- true if rebuilt.
-
getPageN
Gets the dictionary that represents a page.- Parameters:
pageNum- the page number. 1 is the first- Returns:
- the page dictionary
-
getPageNRelease
- Parameters:
pageNum- number of page- Returns:
- a Dictionary object
-
releasePage
public void releasePage(int pageNum) - Parameters:
pageNum- number of page
-
resetReleasePage
public void resetReleasePage() -
getPageOrigRef
Gets the page reference to this page.- Parameters:
pageNum- the page number. 1 is the first- Returns:
- the page reference
-
getPageContent
Gets the contents of the page.- Parameters:
pageNum- the page number. 1 is the firstfile- the location of the PDF document- Returns:
- the content
- Throws:
IOException- on error
-
killXref
-
getStreamBytes
Get the content from a stream applying the required filters.- Parameters:
stream- the stream- Returns:
- the stream content
- Throws:
IOException- on error
-
isTampered
public boolean isTampered()Checks if the document was changed.- Returns:
trueif the document was changed,falseotherwise
-
setTampered
public void setTampered(boolean tampered) Sets the tampered state. A tampered PdfReader cannot be reused in PdfStamper.- Parameters:
tampered- the tampered state
-
getMetadata
Gets the XML metadata.- Returns:
- the XML metadata
- Throws:
IOException- on error
-
getLastXref
public int getLastXref()Gets the byte address of the last xref table.- Returns:
- the byte address of the last xref table
-
getXrefSize
public int getXrefSize()Gets the number of xref objects.- Returns:
- the number of xref objects
-
getEofPos
public int getEofPos()Gets the byte address of the %%EOF marker.- Returns:
- the byte address of the %%EOF marker
-
getPdfVersion
public char getPdfVersion()Gets the PDF version. Only the last version char is returned. For example version 1.4 is returned as '4'.- Returns:
- the PDF version
-
isEncrypted
public boolean isEncrypted()Returnstrueif the PDF is encrypted.- Returns:
trueif the PDF is encrypted
-
getPermissions
public int getPermissions()Gets the encryption permissions. It can be used directly inPdfWriter.setEncryption().- Returns:
- the encryption permissions
-
getTrailer
-
getNamedDestination
Gets all the named destinations as anHashMap. The key is the name and the value is the destinations array.- Returns:
- gets all the named destinations
-
getNamedDestinationFromNames
Gets the named destinations from the /Dests key in the catalog as anHashMap. The key is the name and the value is the destinations array.- Returns:
- gets the named destinations
-
getNamedDestinationFromStrings
Gets the named destinations from the /Names key in the catalog as anHashMap. The key is the name and the value is the destinations array.- Returns:
- gets the named destinations
-
close
public void close()Closes the reader -
getAcroFields
Gets a read-only version ofAcroFields.- Returns:
- a read-only version of
AcroFields
-
getJavaScript
Gets the global document JavaScript.- Returns:
- the global document JavaScript
- Throws:
IOException- on error
-
setViewerPreferences
public void setViewerPreferences(int preferences) Sets the viewer preferences as the sum of several constants.- Specified by:
setViewerPreferencesin interfacePdfViewerPreferences- Parameters:
preferences- the viewer preferences- See Also:
-
addViewerPreference
Adds a viewer preference- Specified by:
addViewerPreferencein interfacePdfViewerPreferences- Parameters:
key- a key for a viewer preferencevalue- a value for the viewer preference- See Also:
-
getSimpleViewerPreferences
public int getSimpleViewerPreferences()Returns a bitset representing the PageMode and PageLayout viewer preferences. Doesn't return any information about the ViewerPreferences dictionary.- Returns:
- an int that contains the Viewer Preferences.
-
isAppendable
public boolean isAppendable()Getter for property appendable.- Returns:
- Value of property appendable.
-
setAppendable
public void setAppendable(boolean appendable) Setter for property appendable.- Parameters:
appendable- New value of property appendable.
-
isNewXrefType
public boolean isNewXrefType()Getter for property newXrefType.- Returns:
- Value of property newXrefType.
-
getFileLength
public int getFileLength()Getter for property fileLength.- Returns:
- Value of property fileLength.
-
isHybridXref
public boolean isHybridXref()Getter for property hybridXref.- Returns:
- Value of property hybridXref.
-
removeUsageRights
public void removeUsageRights()Removes any usage rights that this PDF may have. Only Adobe can grant usage rights and any PDF modification with iText will invalidate them. Invalidated usage rights may confuse Acrobat and it's advisable to remove them altogether. -
getCertificationLevel
public int getCertificationLevel()Gets the certification level for this document. The return values can bePdfSignatureAppearance.NOT_CERTIFIED,PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED,PdfSignatureAppearance.CERTIFIED_FORM_FILLINGandPdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS.No signature validation is made, use the methods available for that in
AcroFields.- Returns:
- gets the certification level for this document
-
isOpenedWithFullPermissions
public final 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. If the document is not encrypted it will returntrue.- Returns:
trueif the document was opened with the owner password or if it's not encrypted,falseif the document was opened with the user password
-
getCryptoMode
public int getCryptoMode() -
isMetadataEncrypted
public boolean isMetadataEncrypted()
-