Package com.aowagie.text.pdf
Class PdfReader
- java.lang.Object
-
- com.aowagie.text.pdf.PdfReader
-
- All Implemented Interfaces:
PdfViewerPreferences
- Direct Known Subclasses:
FdfReader
public class PdfReader extends java.lang.Object implements PdfViewerPreferences
Reads a PDF document.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPdfReader.PageRefs
-
Field Summary
Fields Modifier and Type Field Description private PRAcroFormacroFormprivate booleanacroFormParsedprivate booleanappendableHolds value of property appendable.protected PdfDictionarycatalogprivate java.security.cert.Certificatecertificateprivate java.security.KeycertificateKeyprivate java.lang.StringcertificateKeyProviderprivate booleanconsolidateNamedDestinationsprivate PRIndirectReferencecryptoRefprivate PdfEncryptiondecryptprivate booleanencryptedprivate booleanencryptionErrorprivate static byte[]endobjprivate static byte[]endstreamprivate inteofPosprivate intfileLengthprivate intfreeXrefprivate booleanhybridXrefprivate intlastXrefprivate intlastXrefPartialprivate booleannewXrefTypeprivate intobjGenprivate intobjNumprivate java.util.HashMapobjStmMarkprivate IntHashtableobjStmToOffsetprivate booleanownerPasswordUsedprivate static PdfName[]pageInhCandidates(package private) PdfReader.PageRefspageRefsprivate booleanpartialprivate byte[]passwordprivate charpdfVersionprivate intpValueprivate intreadDepthprivate booleanrebuiltprivate PdfDictionaryrootPagesprivate intrValueprivate booleansharedStreamsprivate java.util.ArrayListstringsprivate booleantamperedprotected PRTokenisertokensprotected PdfDictionarytrailerprivate PdfViewerPreferencesImpviewerPreferencesprivate int[]xrefprivate java.util.ArrayListxrefObj
-
Constructor Summary
Constructors Modifier Constructor Description protectedPdfReader()PdfReader(byte[] pdfIn)Reads and parses a PDF document.PdfReader(byte[] pdfIn, byte[] ownerPassword)Reads and parses a PDF document.(package private)PdfReader(PdfReader reader)Creates an independent duplicate.PdfReader(java.io.InputStream is)Reads and parses a PDF document.privatePdfReader(java.io.InputStream is, byte[] ownerPassword)Reads and parses a PDF document.PdfReader(java.lang.String filename)Reads and parses a PDF document.privatePdfReader(java.lang.String filename, byte[] ownerPassword)Reads and parses a PDF document.PdfReader(java.lang.String filename, java.security.cert.Certificate certificate, java.security.Key certificateKey, java.lang.String certificateKeyProvider)Reads and parses a PDF document.privatePdfReader(java.net.URL url, byte[] ownerPassword)Reads and parses a PDF document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PRIndirectReferenceaddPdfObject(PdfObject obj)voidaddViewerPreference(PdfName key, PdfObject value)Adds a viewer preferenceprivate static byte[]ASCII85Decode(byte[] in)Decodes a stream that has the ASCII85Decode filter.private static byte[]ASCIIHexDecode(byte[] in)Decodes a stream that has the ASCIIHexDecode filter.private voidcheckPRStreamLength(PRStream stream)voidclose()Closes the reader(package private) voidconsolidateNamedDestinations()Replaces all the local named links with the actual destinations.private static byte[]decodePredictor(byte[] in, PdfObject dicPar)private static PdfDictionaryduplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader)private static PdfObjectduplicatePdfObject(PdfObject original, PdfReader newReader)private voideliminateSharedStreams()Eliminates shared streams if they exist.private voidensureXrefSize(int size)private booleanequalsArray(byte[] ar1, byte[] ar2, int size)private static booleanequalsn(byte[] a1, byte[] a2)private static booleanexistsName(PdfDictionary dic, PdfName key, PdfName value)private static byte[]FlateDecode(byte[] in)Decodes a stream that has the FlateDecode filter.static byte[]FlateDecode(byte[] in, boolean strict)A helper to FlateDecode.AcroFieldsgetAcroFields()Gets a read-only version ofAcroFields.PRAcroFormgetAcroForm()Returns the document's acroform, if it has one.(package private) RectanglegetBoxSize(int index, java.lang.String boxName)Gets the box size.PdfDictionarygetCatalog()Returns the document's catalog.intgetCertificationLevel()Gets the certification level for this document.intgetCryptoMode()(package private) PdfIndirectReferencegetCryptoRef()(package private) PdfEncryptiongetDecrypt()intgetEofPos()Gets the byte address of the %%EOF marker.intgetFileLength()Getter for property fileLength.private static java.lang.StringgetFontName(PdfDictionary dic)java.util.HashMapgetInfo()Returns the content of the document information dictionary as aHashMapofString.java.lang.StringgetJavaScript()Gets the global document JavaScript.private java.lang.StringgetJavaScript(RandomAccessFileOrArray file)Gets the global document JavaScript.intgetLastXref()Gets the byte address of the last xref table.byte[]getMetadata()Gets the XML metadata.private static PdfArraygetNameArray(PdfObject obj)java.util.HashMapgetNamedDestination()Gets all the named destinations as anHashMap.private java.util.HashMapgetNamedDestination(boolean keepNames)Gets all the named destinations as anHashMap.java.util.HashMapgetNamedDestinationFromNames()Gets the named destinations from the /Dests key in the catalog as anHashMap.private java.util.HashMapgetNamedDestinationFromNames(boolean keepNames)Gets the named destinations from the /Dests key in the catalog as anHashMap.java.util.HashMapgetNamedDestinationFromStrings()Gets the named destinations from the /Names key in the catalog as anHashMap.(package private) static RectanglegetNormalizedRectangle(PdfArray box)Normalizes aRectangleso that llx and lly are smaller than urx and ury.intgetNumberOfPages()Gets the number of pages in the document.byte[]getPageContent(int pageNum, RandomAccessFileOrArray file)Gets the contents of the page.PdfDictionarygetPageN(int pageNum)Gets the dictionary that represents a page.PdfDictionarygetPageNRelease(int pageNum)PRIndirectReferencegetPageOrigRef(int pageNum)Gets the page reference to this page.intgetPageRotation(int index)Gets the page rotation.intgetPageRotation(PdfDictionary page)RectanglegetPageSize(int index)Gets the page size without taking rotation into account.private RectanglegetPageSize(PdfDictionary page)Gets the page from a page dictionaryRectanglegetPageSizeWithRotation(int index)Gets the page size, taking rotation into account.(package private) RectanglegetPageSizeWithRotation(PdfDictionary page)Gets the rotated page from a page dictionary.PdfObjectgetPdfObject(int idx)static PdfObjectgetPdfObject(PdfObject obj)Reads aPdfObjectresolving an indirect reference if needed.(package private) static PdfObjectgetPdfObject(PdfObject obj, PdfObject parent)(package private) PdfObjectgetPdfObjectRelease(int idx)static PdfObjectgetPdfObjectRelease(PdfObject obj)(package private) static PdfObjectgetPdfObjectRelease(PdfObject obj, PdfObject parent)Reads aPdfObjectresolving an indirect reference if needed.protected PdfReaderInstancegetPdfReaderInstance(PdfWriter writer)chargetPdfVersion()Gets the PDF version.intgetPermissions()Gets the encryption permissions.RandomAccessFileOrArraygetSafeFile()Gets a new file instance of the original PDF document.intgetSimpleViewerPreferences()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.private static byte[]getStreamBytes(PRStream stream, RandomAccessFileOrArray file)Get the content from a stream applying the required filters.(package private) static byte[]getStreamBytesRaw(PRStream stream)Get the content from a stream as it is without applying any filter.private static byte[]getStreamBytesRaw(PRStream stream, RandomAccessFileOrArray file)Get the content from a stream as it is without applying any filter.private static java.lang.StringgetSubsetPrefix(PdfDictionary dic)PdfDictionarygetTrailer()Gets the trailer dictionaryintgetXrefSize()Gets the number of xref objects.booleanisAppendable()Getter for property appendable.booleanisEncrypted()Returnstrueif the PDF is encrypted.booleanisHybridXref()Getter for property hybridXref.booleanisMetadataEncrypted()booleanisNewXrefType()Getter for property newXrefType.booleanisOpenedWithFullPermissions()Checks if the document was opened with the owner password so that the end application can decide what level of access restrictions to apply.booleanisRebuilt()Checks if the document had errors and was rebuilt.booleanisTampered()Checks if the document was changed.private voiditerateBookmarks(PdfObject outlineRef, java.util.HashMap names)(package private) static PdfObjectkillIndirect(PdfObject obj)Eliminates the reference to the object freeing the memory used by it and clearing the xref entry.protected voidkillXref(PdfObject obj)private static byte[]LZWDecode(byte[] in)Decodes a stream that has the LZWDecode filter.private PdfArrayreadArray()private voidreadDecryptedDocObj()private PdfDictionaryreadDictionary()protected voidreadDocObj()private voidreadDocObjPartial()private voidreadObjStm(PRStream stream, IntHashtable map)private PdfObjectreadOneObjStm(PRStream stream, int idx)protected voidreadPages()protected voidreadPdf()private voidreadPdfPartial()private PdfObjectreadPRObject()private PdfObjectreadSingleObject(int k)private voidreadXref()private PdfDictionaryreadXrefSection()private booleanreadXRefStream(int ptr)protected voidrebuildXref()private voidreleaseLastXrefPartial()(package private) static voidreleaseLastXrefPartial(PdfObject obj)voidreleasePage(int pageNum)(package private) voidremoveFields()Removes all the fields from the document.private voidremoveUnusedNode(PdfObject obj, boolean[] hits)private intremoveUnusedObjects()Removes all the unreachable objects.voidremoveUsageRights()Removes any usage rights that this PDF may have.private booleanreplaceNamedDestination(PdfObject obj, java.util.HashMap names)voidresetReleasePage()(package private) voidselectPages(java.util.List pagesToKeep)Selects the pages to keep in the document.voidsetAppendable(boolean appendable)Setter for property appendable.private voidsetPageContent(int pageNum, byte[] content, int compressionLevel)Sets the contents of the page.voidsetTampered(boolean tampered)Sets the tampered state.voidsetViewerPreferences(int preferences)Sets the viewer preferences as the sum of several constants.(package private) voidsetViewerPreferences(PdfViewerPreferencesImp vp)private voidsetXrefPartialObject(int idx, PdfObject obj)(package private) intshuffleSubsetNames()Finds all the font subsets and changes the prefixes to some random values.
-
-
-
Field Detail
-
pageInhCandidates
private static final PdfName[] pageInhCandidates
-
endstream
private static final byte[] endstream
-
endobj
private static final byte[] endobj
-
tokens
protected PRTokeniser tokens
-
xref
private int[] xref
-
objStmMark
private java.util.HashMap objStmMark
-
objStmToOffset
private IntHashtable objStmToOffset
-
newXrefType
private boolean newXrefType
-
xrefObj
private java.util.ArrayList xrefObj
-
rootPages
private PdfDictionary rootPages
-
trailer
protected PdfDictionary trailer
-
catalog
protected PdfDictionary catalog
-
pageRefs
PdfReader.PageRefs pageRefs
-
acroForm
private PRAcroForm acroForm
-
acroFormParsed
private boolean acroFormParsed
-
encrypted
private boolean encrypted
-
rebuilt
private boolean rebuilt
-
freeXref
private int freeXref
-
tampered
private boolean tampered
-
lastXref
private int lastXref
-
eofPos
private int eofPos
-
pdfVersion
private char pdfVersion
-
decrypt
private PdfEncryption decrypt
-
password
private byte[] password
-
certificateKey
private java.security.Key certificateKey
-
certificate
private java.security.cert.Certificate certificate
-
certificateKeyProvider
private java.lang.String certificateKeyProvider
-
ownerPasswordUsed
private boolean ownerPasswordUsed
-
strings
private final java.util.ArrayList strings
-
sharedStreams
private boolean sharedStreams
-
consolidateNamedDestinations
private boolean consolidateNamedDestinations
-
rValue
private int rValue
-
pValue
private int pValue
-
objNum
private int objNum
-
objGen
private int objGen
-
fileLength
private int fileLength
-
hybridXref
private boolean hybridXref
-
lastXrefPartial
private int lastXrefPartial
-
partial
private boolean partial
-
cryptoRef
private PRIndirectReference cryptoRef
-
viewerPreferences
private final PdfViewerPreferencesImp viewerPreferences
-
encryptionError
private boolean encryptionError
-
appendable
private boolean appendable
Holds value of property appendable.
-
readDepth
private int readDepth
-
-
Constructor Detail
-
PdfReader
protected PdfReader()
-
PdfReader
public PdfReader(java.lang.String filename) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
filename- the file name of the document- Throws:
java.io.IOException- on error
-
PdfReader
private PdfReader(java.lang.String filename, byte[] ownerPassword) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
filename- the file name of the documentownerPassword- the password to read the document- Throws:
java.io.IOException- on error
-
PdfReader
public PdfReader(byte[] pdfIn) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
pdfIn- the byte array with the document- Throws:
java.io.IOException- on error
-
PdfReader
public PdfReader(byte[] pdfIn, byte[] ownerPassword) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
pdfIn- the byte array with the documentownerPassword- the password to read the document- Throws:
java.io.IOException- on error
-
PdfReader
public PdfReader(java.lang.String filename, java.security.cert.Certificate certificate, java.security.Key certificateKey, java.lang.String certificateKeyProvider) throws java.io.IOExceptionReads 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:
java.io.IOException- on error
-
PdfReader
private PdfReader(java.net.URL url, byte[] ownerPassword) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
url- the URL of the documentownerPassword- the password to read the document- Throws:
java.io.IOException- on error
-
PdfReader
private PdfReader(java.io.InputStream is, byte[] ownerPassword) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
is- theInputStreamcontaining the document. The stream is read to the end but is not closedownerPassword- the password to read the document- Throws:
java.io.IOException- on error
-
PdfReader
public PdfReader(java.io.InputStream is) throws java.io.IOExceptionReads and parses a PDF document.- Parameters:
is- theInputStreamcontaining the document. The stream is read to the end but is not closed- Throws:
java.io.IOException- on error
-
PdfReader
PdfReader(PdfReader reader)
Creates an independent duplicate.- Parameters:
reader- thePdfReaderto duplicate
-
-
Method Detail
-
getSafeFile
public RandomAccessFileOrArray getSafeFile()
Gets a new file instance of the original PDF document.- Returns:
- a new file instance of the original PDF document
-
getPdfReaderInstance
protected PdfReaderInstance getPdfReaderInstance(PdfWriter writer)
-
getNumberOfPages
public int getNumberOfPages()
Gets the number of pages in the document.- Returns:
- the number of pages in the document
-
getCatalog
public PdfDictionary 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
public PRAcroForm 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
public int getPageRotation(PdfDictionary page)
-
getPageSizeWithRotation
public Rectangle getPageSizeWithRotation(int index)
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.
-
getPageSizeWithRotation
Rectangle getPageSizeWithRotation(PdfDictionary page)
Gets the rotated page from a page dictionary.- Parameters:
page- the page dictionary- Returns:
- the rotated page
-
getPageSize
public Rectangle getPageSize(int index)
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
-
getPageSize
private Rectangle getPageSize(PdfDictionary page)
Gets the page from a page dictionary- Parameters:
page- the page dictionary- Returns:
- the page
-
getBoxSize
Rectangle getBoxSize(int index, java.lang.String boxName)
Gets the box size. Allowed names are: "crop", "trim", "art", "bleed" and "media".- Parameters:
index- the page number. The first page is 1boxName- the box name- Returns:
- the box rectangle or null
-
getInfo
public java.util.HashMap getInfo()
Returns the content of the document information dictionary as aHashMapofString.- Returns:
- content of the document information dictionary
-
getNormalizedRectangle
static Rectangle getNormalizedRectangle(PdfArray box)
Normalizes aRectangleso that llx and lly are smaller than urx and ury.- Parameters:
box- the original rectangle- Returns:
- a normalized
Rectangle
-
readPdf
protected void readPdf() throws java.io.IOException- Throws:
java.io.IOException
-
readPdfPartial
private void readPdfPartial() throws java.io.IOException- Throws:
java.io.IOException
-
equalsArray
private boolean equalsArray(byte[] ar1, byte[] ar2, int size)
-
readDecryptedDocObj
private void readDecryptedDocObj() throws java.io.IOException- Throws:
java.io.IOException
-
getPdfObjectRelease
public static PdfObject getPdfObjectRelease(PdfObject obj)
- Parameters:
obj- object to release- Returns:
- a PdfObject
-
getPdfObject
public static PdfObject getPdfObject(PdfObject obj)
Reads aPdfObjectresolving an indirect reference if needed.- Parameters:
obj- thePdfObjectto read- Returns:
- the resolved
PdfObject
-
getPdfObjectRelease
static PdfObject getPdfObjectRelease(PdfObject obj, PdfObject parent)
Reads aPdfObjectresolving an indirect reference if needed. If the reader was opened in partial mode the object will be released to save memory.- Parameters:
obj- thePdfObjectto readparent-- Returns:
- a PdfObject
-
getPdfObject
static PdfObject getPdfObject(PdfObject obj, PdfObject parent)
- Parameters:
obj-parent-- Returns:
- a PdfObject
-
getPdfObjectRelease
PdfObject getPdfObjectRelease(int idx)
- Parameters:
idx-- Returns:
- a PdfObject
-
getPdfObject
public PdfObject getPdfObject(int idx)
- Parameters:
idx- index to get- Returns:
- aPdfObject returns a PdfObject
-
releaseLastXrefPartial
private void releaseLastXrefPartial()
-
releaseLastXrefPartial
static void releaseLastXrefPartial(PdfObject obj)
- Parameters:
obj-
-
setXrefPartialObject
private void setXrefPartialObject(int idx, PdfObject obj)
-
addPdfObject
public PRIndirectReference addPdfObject(PdfObject obj)
- Parameters:
obj- object to add- Returns:
- an indirect reference
-
readPages
protected void readPages() throws java.io.IOException- Throws:
java.io.IOException
-
readDocObjPartial
private void readDocObjPartial() throws java.io.IOException- Throws:
java.io.IOException
-
readSingleObject
private PdfObject readSingleObject(int k) throws java.io.IOException
- Throws:
java.io.IOException
-
readOneObjStm
private PdfObject readOneObjStm(PRStream stream, int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
readDocObj
protected void readDocObj() throws java.io.IOException- Throws:
java.io.IOException
-
checkPRStreamLength
private void checkPRStreamLength(PRStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
readObjStm
private void readObjStm(PRStream stream, IntHashtable map) throws java.io.IOException
- Throws:
java.io.IOException
-
killIndirect
static PdfObject killIndirect(PdfObject obj)
Eliminates the reference to the object freeing the memory used by it and clearing the xref entry.- Parameters:
obj- the object. If it's an indirect reference it will be eliminated- Returns:
- the object or the already erased dereferenced object
-
ensureXrefSize
private void ensureXrefSize(int size)
-
readXref
private void readXref() throws java.io.IOException- Throws:
java.io.IOException
-
readXrefSection
private PdfDictionary readXrefSection() throws java.io.IOException
- Throws:
java.io.IOException
-
readXRefStream
private boolean readXRefStream(int ptr) throws java.io.IOException- Throws:
java.io.IOException
-
rebuildXref
protected void rebuildXref() throws java.io.IOException- Throws:
java.io.IOException
-
readDictionary
private PdfDictionary readDictionary() throws java.io.IOException
- Throws:
java.io.IOException
-
readArray
private PdfArray readArray() throws java.io.IOException
- Throws:
java.io.IOException
-
readPRObject
private PdfObject readPRObject() throws java.io.IOException
- Throws:
java.io.IOException
-
FlateDecode
private static byte[] FlateDecode(byte[] in)
Decodes a stream that has the FlateDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
decodePredictor
private static byte[] decodePredictor(byte[] in, PdfObject dicPar)- Parameters:
in-dicPar-- Returns:
- a byte array
-
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
-
ASCIIHexDecode
private static byte[] ASCIIHexDecode(byte[] in)
Decodes a stream that has the ASCIIHexDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
ASCII85Decode
private static byte[] ASCII85Decode(byte[] in)
Decodes a stream that has the ASCII85Decode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
LZWDecode
private static byte[] LZWDecode(byte[] in)
Decodes a stream that has the LZWDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
isRebuilt
public boolean isRebuilt()
Checks if the document had errors and was rebuilt.- Returns:
- true if rebuilt.
-
getPageN
public PdfDictionary getPageN(int pageNum)
Gets the dictionary that represents a page.- Parameters:
pageNum- the page number. 1 is the first- Returns:
- the page dictionary
-
getPageNRelease
public PdfDictionary getPageNRelease(int pageNum)
- 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
public PRIndirectReference getPageOrigRef(int pageNum)
Gets the page reference to this page.- Parameters:
pageNum- the page number. 1 is the first- Returns:
- the page reference
-
getPageContent
public byte[] getPageContent(int pageNum, RandomAccessFileOrArray file) throws java.io.IOExceptionGets the contents of the page.- Parameters:
pageNum- the page number. 1 is the firstfile- the location of the PDF document- Returns:
- the content
- Throws:
java.io.IOException- on error
-
killXref
protected void killXref(PdfObject obj)
-
setPageContent
private void setPageContent(int pageNum, byte[] content, int compressionLevel)Sets the contents of the page.- Parameters:
content- the new page contentpageNum- the page number. 1 is the first- Since:
- 2.1.3 (the method already existed without param compressionLevel)
-
getStreamBytes
private static byte[] getStreamBytes(PRStream stream, RandomAccessFileOrArray file) throws java.io.IOException
Get the content from a stream applying the required filters.- Parameters:
stream- the streamfile- the location where the stream is- Returns:
- the stream content
- Throws:
java.io.IOException- on error
-
getStreamBytes
public static byte[] getStreamBytes(PRStream stream) throws java.io.IOException
Get the content from a stream applying the required filters.- Parameters:
stream- the stream- Returns:
- the stream content
- Throws:
java.io.IOException- on error
-
getStreamBytesRaw
private static byte[] getStreamBytesRaw(PRStream stream, RandomAccessFileOrArray file) throws java.io.IOException
Get the content from a stream as it is without applying any filter.- Parameters:
stream- the streamfile- the location where the stream is- Returns:
- the stream content
- Throws:
java.io.IOException- on error
-
getStreamBytesRaw
static byte[] getStreamBytesRaw(PRStream stream) throws java.io.IOException
Get the content from a stream as it is without applying any filter.- Parameters:
stream- the stream- Returns:
- the stream content
- Throws:
java.io.IOException- on error
-
eliminateSharedStreams
private void eliminateSharedStreams()
Eliminates shared streams if they exist.
-
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
public byte[] getMetadata() throws java.io.IOExceptionGets the XML metadata.- Returns:
- the XML metadata
- Throws:
java.io.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
public PdfDictionary getTrailer()
Gets the trailer dictionary- Returns:
- the trailer dictionary
-
getDecrypt
PdfEncryption getDecrypt()
-
equalsn
private static boolean equalsn(byte[] a1, byte[] a2)
-
existsName
private static boolean existsName(PdfDictionary dic, PdfName key, PdfName value)
-
getFontName
private static java.lang.String getFontName(PdfDictionary dic)
-
getSubsetPrefix
private static java.lang.String getSubsetPrefix(PdfDictionary dic)
-
shuffleSubsetNames
int shuffleSubsetNames()
Finds all the font subsets and changes the prefixes to some random values.- Returns:
- the number of font subsets altered
-
getNamedDestination
public java.util.HashMap 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
-
getNamedDestination
private java.util.HashMap getNamedDestination(boolean keepNames)
Gets all the named destinations as anHashMap. The key is the name and the value is the destinations array.- Parameters:
keepNames- true if you want the keys to be real PdfNames instead of Strings- Returns:
- gets all the named destinations
- Since:
- 2.1.6
-
getNamedDestinationFromNames
public java.util.HashMap 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
-
getNamedDestinationFromNames
private java.util.HashMap getNamedDestinationFromNames(boolean keepNames)
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.- Parameters:
keepNames- true if you want the keys to be real PdfNames instead of Strings- Returns:
- gets the named destinations
- Since:
- 2.1.6
-
getNamedDestinationFromStrings
public java.util.HashMap 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
-
replaceNamedDestination
private boolean replaceNamedDestination(PdfObject obj, java.util.HashMap names)
-
removeFields
void removeFields()
Removes all the fields from the document.
-
iterateBookmarks
private void iterateBookmarks(PdfObject outlineRef, java.util.HashMap names)
-
consolidateNamedDestinations
void consolidateNamedDestinations()
Replaces all the local named links with the actual destinations.
-
duplicatePdfDictionary
private static PdfDictionary duplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader)
-
duplicatePdfObject
private static PdfObject duplicatePdfObject(PdfObject original, PdfReader newReader)
-
close
public void close()
Closes the reader
-
removeUnusedNode
private void removeUnusedNode(PdfObject obj, boolean[] hits)
-
removeUnusedObjects
private int removeUnusedObjects()
Removes all the unreachable objects.- Returns:
- the number of indirect objects removed
-
getAcroFields
public AcroFields getAcroFields()
Gets a read-only version ofAcroFields.- Returns:
- a read-only version of
AcroFields
-
getJavaScript
private java.lang.String getJavaScript(RandomAccessFileOrArray file) throws java.io.IOException
Gets the global document JavaScript.- Parameters:
file- the document file- Returns:
- the global document JavaScript
- Throws:
java.io.IOException- on error
-
getJavaScript
public java.lang.String getJavaScript() throws java.io.IOExceptionGets the global document JavaScript.- Returns:
- the global document JavaScript
- Throws:
java.io.IOException- on error
-
selectPages
void selectPages(java.util.List pagesToKeep)
Selects the pages to keep in the document. The pages are described as aListofInteger. The page ordering can be changed but no page repetitions are allowed. Note that it may be very slow in partial mode.- Parameters:
pagesToKeep- the pages to keep in the document
-
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:
PdfViewerPreferences.setViewerPreferences(int)
-
addViewerPreference
public void addViewerPreference(PdfName key, PdfObject value)
Adds a viewer preference- Specified by:
addViewerPreferencein interfacePdfViewerPreferences- Parameters:
key- a key for a viewer preferencevalue- a value for the viewer preference- See Also:
PdfViewerPreferences.addViewerPreference(com.aowagie.text.pdf.PdfName, com.aowagie.text.pdf.PdfObject)
-
setViewerPreferences
void setViewerPreferences(PdfViewerPreferencesImp vp)
-
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.
-
getCryptoRef
PdfIndirectReference getCryptoRef()
-
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()
-
-