Class PdfReader
java.lang.Object
com.itextpdf.text.pdf.PdfReader
- All Implemented Interfaces:
PdfViewerPreferences
- Direct Known Subclasses:
AcroFields.ContentsChecker, FdfReader
Reads a PDF document.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PRAcroFormprotected booleanprivate booleanHolds value of property appendable.protected PdfDictionaryprotected Certificateprotected Keyprotected Stringprotected booleanprotected static Counterprivate PRIndirectReferencestatic booleanprotected PdfEncryptionprotected booleanprivate boolean(package private) static final byte[](package private) static final byte[]protected longprotected ExternalDecryptionProcessprivate longprotected intprivate booleanprotected longprivate intprivate static final Logger(package private) MemoryLimitsAwareHandlerHandler which will be used for decompression of pdf streams.protected booleanprivate intprivate intprotected HashMap<Integer, IntHashtable> protected LongHashtableprivate boolean(package private) static final PdfName[]protected PdfReader.PageRefsprivate booleanprotected byte[]protected charprotected longprivate intprotected booleanprotected boolean(package private) PdfDictionaryprotected intprotected booleanprotected booleanprotected PRTokeniserprotected PdfDictionarystatic booleanThe iText developers are not responsible if you decide to change the value of this static parameter.private final PdfViewerPreferencesImpprotected long[] -
Constructor Summary
ConstructorsModifierConstructorDescriptionPdfReader(byte[] pdfIn) Reads and parses a PDF document.PdfReader(byte[] pdfIn, byte[] ownerPassword) Reads and parses a PDF document.PdfReader(byte[] pdfIn, Certificate certificate, ExternalDecryptionProcess externalDecryptionProcess) Reads and parses a PDF document.privatePdfReader(RandomAccessSource byteSource, boolean partialRead, byte[] ownerPassword, Certificate certificate, Key certificateKey, String certificateKeyProvider, ExternalDecryptionProcess externalDecryptionProcess, boolean closeSourceOnConstructorError) Constructs a new PdfReader.privatePdfReader(RandomAccessSource byteSource, ReaderProperties properties) Constructs a new PdfReader.Creates an independent duplicate.PdfReader(RandomAccessFileOrArray raf, byte[] ownerPassword) Reads and parses a pdf document.PdfReader(RandomAccessFileOrArray raf, byte[] ownerPassword, boolean partial) Reads and parses a pdf document.PdfReader(ReaderProperties properties, RandomAccessFileOrArray raf) Reads and parses a PDF document.PdfReader(ReaderProperties properties, InputStream is) Reads and parses a PDF document.PdfReader(ReaderProperties properties, String filename) Reads and parses a PDF document.PdfReader(InputStream is) Reads and parses a PDF document.PdfReader(InputStream is, byte[] ownerPassword) Reads and parses a PDF document.PdfReader(InputStream inputStream, Certificate certificate, ExternalDecryptionProcess externalDecryptionProcess) Reads and parses a PDF document.Reads and parses a PDF document.Reads and parses a PDF document.Reads and parses a PDF document.PdfReader(String filename, Certificate certificate, ExternalDecryptionProcess externalDecryptionProcess) Reads and parses a PDF document.PdfReader(String filename, Certificate certificate, Key certificateKey, String certificateKeyProvider) Reads and parses a PDF document.Reads and parses a PDF document.Reads and parses a PDF document. -
Method Summary
Modifier and TypeMethodDescriptionaddPdfObject(PdfObject obj) voidaddViewerPreference(PdfName key, PdfObject value) Adds a viewer preferencestatic byte[]ASCII85Decode(byte[] in) Decodes a stream that has the ASCII85Decode filter.(package private) static byte[]ASCII85Decode(byte[] in, ByteArrayOutputStream out) static byte[]ASCIIHexDecode(byte[] in) Decodes a stream that has the ASCIIHexDecode filter.(package private) static byte[]ASCIIHexDecode(byte[] in, ByteArrayOutputStream out) private voidcheckPRStreamLength(PRStream stream) voidclose()Closes the reader, and any underlying stream or data source used to create the readerbyte[]Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 encryption algorithm.voidReplaces all the local named links with the actual destinations.private booleanconvertNamedDestination(PdfObject obj, HashMap<Object, PdfObject> names) Converts a remote named destination GoToR with a local named destination if there's a corresponding name.intFinds all the fonts not subset but embedded and marks them as subset.static byte[]decodeBytes(byte[] b, PdfDictionary streamDictionary) Decode a byte[] applying the filters specified in the provided dictionary using default filter handlers.static byte[]decodeBytes(byte[] b, PdfDictionary streamDictionary, Map<PdfName, FilterHandlers.FilterHandler> filterHandlers) Decode a byte[] applying the filters specified in the provided dictionary using the provided filter handlers.static byte[]decodePredictor(byte[] in, PdfObject dicPar) doubledumpPerc()protected static PdfDictionaryduplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader) protected static PdfObjectduplicatePdfObject(PdfObject original, PdfReader newReader) voidEliminates shared streams if they exist.private voidensureXrefSize(int size) private booleanequalsArray(byte[] ar1, byte[] ar2, int size) (package private) static booleanequalsn(byte[] a1, byte[] a2) (package private) static booleanexistsName(PdfDictionary dic, PdfName key, PdfName value) static byte[]FlateDecode(byte[] in) Decodes a stream that has the FlateDecode filter.static byte[]FlateDecode(byte[] in, boolean strict) A helper to FlateDecode.private static byte[]FlateDecode(byte[] in, boolean strict, ByteArrayOutputStream out) (package private) static byte[]FlateDecode(byte[] in, ByteArrayOutputStream out) Decodes a stream that has the FlateDecode filter.Gets a read-only version ofAcroFields.Returns the document's acroform, if it has one.getBoxSize(int index, String boxName) Gets the box size.Returns the document's catalog.intGets the certification level for this document.protected CountergetCropBox(int index) Gets the crop box without taking rotation into account.int(package private) PdfIndirectReference(package private) PdfEncryptionlongGets the byte address of the %%EOF marker.longGetter for property fileLength.(package private) static StringgetFontName(PdfDictionary dic) getInfo()Returns the content of the document information dictionary as aHashMapofString.Gets the global document JavaScript.Gets the global document JavaScript.longGets the byte address of the last xref table.getLinks(int page) Retrieves links for a certain page.(package private) MemoryLimitsAwareHandlerbyte[]Gets the XML metadata.private static PdfArraygetNameArray(PdfObject obj) Gets all the named destinations as anHashMap.getNamedDestination(boolean keepNames) Gets all the named destinations as anHashMap.Gets the named destinations from the /Dests key in the catalog as anHashMap.getNamedDestinationFromNames(boolean keepNames) 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.static RectangleNormalizes aRectangleso that llx and lly are smaller than urx and ury.intGets the number of pages in the document.private static PRTokenisergetOffsetTokeniser(RandomAccessSource byteSource) Utility method that checks the provided byte source to see if it has junk bytes at the beginning.byte[]getPageContent(int pageNum) Gets the contents of the page.byte[]getPageContent(int pageNum, RandomAccessFileOrArray file) Gets the contents of the page.static byte[]getPageContent(PdfDictionary page) Gets the content from the page dictionary.getPageN(int pageNum) Gets the dictionary that represents a page.getPageNRelease(int pageNum) getPageOrigRef(int pageNum) Gets the page reference to this page.getPageResources(int pageNum) Retrieve the given page's resource dictionarygetPageResources(PdfDictionary pageDict) Retrieve the given page's resource dictionaryintgetPageRotation(int index) Gets the page rotation.(package private) intgetPageRotation(PdfDictionary page) getPageSize(int index) Gets the page size without taking rotation into account.getPageSize(PdfDictionary page) Gets the page from a page dictionarygetPageSizeWithRotation(int index) Gets the page size, taking rotation into account.Gets the rotated page from a page dictionary.getPdfObject(int idx) static PdfObjectgetPdfObject(PdfObject obj) Reads aPdfObjectresolving an indirect reference if needed.static PdfObjectgetPdfObject(PdfObject obj, PdfObject parent) getPdfObjectRelease(int idx) static PdfObjectstatic PdfObjectgetPdfObjectRelease(PdfObject obj, PdfObject parent) Reads aPdfObjectresolving an indirect reference if needed.protected PdfReaderInstancegetPdfReaderInstance(PdfWriter writer) charGets the PDF version.longGets 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.static byte[]getStreamBytes(PRStream stream, RandomAccessFileOrArray file) Get the content from a stream applying the required filters.static byte[]getStreamBytesRaw(PRStream stream) Get the content from a stream as it is without applying any filter.static byte[]getStreamBytesRaw(PRStream stream, RandomAccessFileOrArray file) Get the content from a stream as it is without applying any filter.(package private) static StringGets the trailer dictionaryintGets the number of xref objects.booleanChecks if this PDF has usage rights enabled.booleanis128Key()Returnstrueif the PDF has a 128 bit key encryption.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.booleanisTagged()Checks if the PDF is a tagged PDF.booleanChecks if the document was changed.private voiditerateBookmarks(PdfObject outlineRef, HashMap<Object, PdfObject> names) static PdfObjectkillIndirect(PdfObject obj) Eliminates the reference to the object freeing the memory used by it and clearing the xref entry.protected voidstatic byte[]LZWDecode(byte[] in) Decodes a stream that has the LZWDecode filter.(package private) static byte[]LZWDecode(byte[] in, ByteArrayOutputStream out) voidReplaces remote named links with local destinations that have the same name.protected PdfArrayprivate voidprotected PdfDictionaryprotected voidprotected voidprotected voidreadObjStm(PRStream stream, IntHashtable map) protected PdfObjectreadOneObjStm(PRStream stream, int idx) protected voidprotected voidreadPdf()Parses the entire PDFprotected voidPartially parses the pdfprotected PdfObjectprotected PdfObjectreadSingleObject(int k) protected voidreadXref()protected PdfDictionaryprotected booleanreadXRefStream(long ptr) protected voidvoidstatic voidvoidreleasePage(int pageNum) voidRemoves all the annotations and fields from the document.voidRemoves all the fields from the document.protected voidremoveUnusedNode(PdfObject obj, boolean[] hits) intRemoves all the unreachable objects.voidRemoves any usage rights that this PDF may have.private booleanreplaceNamedDestination(PdfObject obj, HashMap<Object, PdfObject> names) voidvoidvoidselectPages(String ranges) Selects the pages to keep in the document.voidselectPages(List<Integer> pagesToKeep) Selects the pages to keep in the document.protected voidselectPages(List<Integer> pagesToKeep, boolean removeUnused) Selects the pages to keep in the document.voidsetAppendable(boolean appendable) Setter for property appendable.voidsetPageContent(int pageNum, byte[] content) Sets the contents of the page.voidsetPageContent(int pageNum, byte[] content, int compressionLevel) Sets the contents of the page.voidsetPageContent(int pageNum, byte[] content, int compressionLevel, boolean killOldXRefRecursively) 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.voidprivate voidsetXrefPartialObject(int idx, PdfObject obj) intFinds all the font subsets and changes the prefixes to some random values.
-
Field Details
-
unethicalreading
public static boolean unethicalreadingThe iText developers are not responsible if you decide to change the value of this static parameter.- Since:
- 5.0.2
-
debugmode
public static boolean debugmode -
LOGGER
-
pageInhCandidates
-
endstream
static final byte[] endstream -
endobj
static final byte[] endobj -
tokens
-
xref
protected long[] xref -
objStmMark
-
objStmToOffset
-
newXrefType
protected boolean newXrefType -
xrefObj
-
rootPages
PdfDictionary rootPages -
trailer
-
catalog
-
pageRefs
-
acroForm
-
acroFormParsed
protected boolean acroFormParsed -
encrypted
protected boolean encrypted -
rebuilt
protected boolean rebuilt -
freeXref
protected int freeXref -
tampered
protected boolean tampered -
lastXref
protected long lastXref -
eofPos
protected long eofPos -
pdfVersion
protected char pdfVersion -
decrypt
-
password
protected byte[] password -
certificateKey
-
certificate
-
certificateKeyProvider
-
externalDecryptionProcess
-
ownerPasswordUsed
private boolean ownerPasswordUsed -
strings
-
consolidateNamedDestinations
protected boolean consolidateNamedDestinations -
remoteToLocalNamedDestinations
protected boolean remoteToLocalNamedDestinations -
rValue
protected int rValue -
pValue
protected long pValue -
objNum
private int objNum -
objGen
private int objGen -
fileLength
private long fileLength -
hybridXref
private boolean hybridXref -
lastXrefPartial
private int lastXrefPartial -
partial
private boolean partial -
cryptoRef
-
viewerPreferences
-
encryptionError
private boolean encryptionError -
memoryLimitsAwareHandler
MemoryLimitsAwareHandler memoryLimitsAwareHandlerHandler which will be used for decompression of pdf streams. -
appendable
private boolean appendableHolds value of property appendable. -
COUNTER
-
readDepth
private int readDepth
-
-
Constructor Details
-
PdfReader
private PdfReader(RandomAccessSource byteSource, boolean partialRead, byte[] ownerPassword, Certificate certificate, Key certificateKey, String certificateKeyProvider, ExternalDecryptionProcess externalDecryptionProcess, boolean closeSourceOnConstructorError) throws IOException Constructs a new PdfReader. This is the master constructor.- Parameters:
byteSource- source of bytes for the readerpartialRead- if true, the reader is opened in partial mode (PDF is parsed on demand), if false, the entire PDF is parsed into memory as the reader opensownerPassword- the password or null if no password is requiredcertificate- the certificate or null if no certificate is requiredcertificateKey- the key or null if no certificate key is requiredcertificateKeyProvider- the name of the key provider, or null if no key is requiredexternalDecryptionProcess-closeSourceOnConstructorError- if true, the byteSource will be closed if there is an error during construction of this reader- Throws:
IOException
-
PdfReader
Constructs a new PdfReader. This is the master constructor.- Parameters:
byteSource- source of bytes for the readerproperties- the properties which will be used to create the reader- Throws:
IOException
-
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:
properties- the properties which will be used to create the readerfilename- the file name of the document- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
filename- the file name of the documentownerPassword- the password to read the document- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
filename- the file name of the documentownerPassword- the password to read the documentpartial- indicates if the reader needs to read the document only partially- 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
public PdfReader(String filename, Certificate certificate, ExternalDecryptionProcess externalDecryptionProcess) throws IOException Reads and parses a PDF document.- Parameters:
filename- the file name of the documentcertificate-externalDecryptionProcess-- Throws:
IOException- on error
-
PdfReader
public PdfReader(byte[] pdfIn, Certificate certificate, ExternalDecryptionProcess externalDecryptionProcess) throws IOException Reads and parses a PDF document.- Parameters:
pdfIn- the document as a byte arraycertificate-externalDecryptionProcess-- Throws:
IOException- on error
-
PdfReader
public PdfReader(InputStream inputStream, Certificate certificate, ExternalDecryptionProcess externalDecryptionProcess) throws IOException Reads and parses a PDF document.- Parameters:
inputStream- the PDF filecertificate-externalDecryptionProcess-- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
url- the URL of the document- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
url- the URL of the documentownerPassword- the password to read the document- 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 closedownerPassword- the password to read the document- 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
-
PdfReader
Reads and parses a PDF document.- Parameters:
properties- the properties which will be used to create the readeris- theInputStreamcontaining the document. The stream is read to the end but is not closed- Throws:
IOException- on error
-
PdfReader
Reads and parses a PDF document.- Parameters:
properties- the properties which will be used to create the readerraf- the document location- Throws:
IOException- on error
-
PdfReader
Reads and parses a pdf document. Contrary to the other constructors only the xref is read into memory. The reader is said to be working in "partial" mode as only parts of the pdf are read as needed.- Parameters:
raf- the document locationownerPassword- the password ornullfor no password- Throws:
IOException- on error
-
PdfReader
public PdfReader(RandomAccessFileOrArray raf, byte[] ownerPassword, boolean partial) throws IOException Reads and parses a pdf document.- Parameters:
raf- the document locationownerPassword- the password ornullfor no passwordpartial- indicates if the reader needs to read the document only partially. SeePdfReader(RandomAccessFileOrArray, byte[])- Throws:
IOException- on error
-
PdfReader
Creates an independent duplicate.- Parameters:
reader- thePdfReaderto duplicate
-
-
Method Details
-
getCounter
-
getOffsetTokeniser
Utility method that checks the provided byte source to see if it has junk bytes at the beginning. If junk bytes are found, construct a tokeniser that ignores the junk. Otherwise, construct a tokeniser for the byte source as it is- Parameters:
byteSource- the source to check- Returns:
- a tokeniser that is guaranteed to start at the PDF header
- Throws:
IOException- if there is a problem reading the byte source
-
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. Partial mode: return the value stored in the COUNT field of the pageref Full mode: return the total number of pages found while loading in the entire 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
-
getMemoryLimitsAwareHandler
MemoryLimitsAwareHandler getMemoryLimitsAwareHandler() -
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
-
getPageSizeWithRotation
Gets the rotated page from a page dictionary.- Parameters:
page- the page dictionary- Returns:
- the rotated page
-
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
-
getPageSize
Gets the page from a page dictionary- Parameters:
page- the page dictionary- Returns:
- the page
-
getCropBox
Gets the crop box without taking rotation into account. This is the value of the /CropBox key. The crop box is the part of the document to be displayed or printed. It usually is the same as the media box but may be smaller. If the page doesn't have a crop box the page size will be returned.- Parameters:
index- the page number. The first page is 1- Returns:
- the crop box
-
getBoxSize
-
getInfo
-
getNormalizedRectangle
-
isTagged
public boolean isTagged()Checks if the PDF is a tagged PDF. -
readPdf
-
readPdfPartial
-
equalsArray
private boolean equalsArray(byte[] ar1, byte[] ar2, int size) -
readDecryptedDocObj
- Throws:
IOException
-
getPdfObjectRelease
-
getPdfObject
-
getPdfObjectRelease
-
getPdfObject
-
getPdfObjectRelease
- Parameters:
idx-- Returns:
- a PdfObject
-
getPdfObject
- Parameters:
idx-- Returns:
- aPdfObject
-
resetLastXrefPartial
public void resetLastXrefPartial() -
releaseLastXrefPartial
public void releaseLastXrefPartial() -
releaseLastXrefPartial
- Parameters:
obj-
-
setXrefPartialObject
-
addPdfObject
- Parameters:
obj-- Returns:
- an indirect reference
-
readPages
- Throws:
IOException
-
readDocObjPartial
- Throws:
IOException
-
readSingleObject
- Throws:
IOException
-
readOneObjStm
- Throws:
IOException
-
dumpPerc
public double dumpPerc()- Returns:
- the percentage of the cross reference table that has been read
-
readDocObj
- Throws:
IOException
-
checkPRStreamLength
- Throws:
IOException
-
readObjStm
- Throws:
IOException
-
killIndirect
-
ensureXrefSize
private void ensureXrefSize(int size) -
readXref
- Throws:
IOException
-
readXrefSection
- Throws:
IOException
-
readXRefStream
- Throws:
IOException
-
rebuildXref
- Throws:
IOException
-
readDictionary
- Throws:
IOException
-
readArray
- Throws:
IOException
-
readPRObject
- Throws:
IOException
-
FlateDecode
public static byte[] FlateDecode(byte[] in) Decodes a stream that has the FlateDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
FlateDecode
Decodes a stream that has the FlateDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
decodePredictor
- 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
-
FlateDecode
-
ASCIIHexDecode
public static byte[] ASCIIHexDecode(byte[] in) Decodes a stream that has the ASCIIHexDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
ASCIIHexDecode
-
ASCII85Decode
public static byte[] ASCII85Decode(byte[] in) Decodes a stream that has the ASCII85Decode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
ASCII85Decode
-
LZWDecode
public static byte[] LZWDecode(byte[] in) Decodes a stream that has the LZWDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
LZWDecode
-
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-- Returns:
- a Dictionary object
-
releasePage
public void releasePage(int pageNum) - Parameters:
pageNum-
-
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
-
getPageContent
Gets the content from the page dictionary.- Parameters:
page- the page dictionary- Returns:
- the content
- Throws:
IOException- on error- Since:
- 5.0.6
-
getPageResources
Retrieve the given page's resource dictionary- Parameters:
pageNum- 1-based page number from which to retrieve the resource dictionary- Returns:
- The page's resources, or 'null' if the page has none.
- Since:
- 5.1
-
getPageResources
Retrieve the given page's resource dictionary- Parameters:
pageDict- the given page- Returns:
- The page's resources, or 'null' if the page has none.
- Since:
- 5.1
-
getPageContent
Gets the contents of the page.- Parameters:
pageNum- the page number. 1 is the first- Returns:
- the content
- Throws:
IOException- on error
-
killXref
-
setPageContent
public void setPageContent(int pageNum, byte[] content) Sets the contents of the page.- Parameters:
pageNum- the page number. 1 is the firstcontent- the new page content
-
setPageContent
public void setPageContent(int pageNum, byte[] content, int compressionLevel) Sets the contents of the page.- Parameters:
pageNum- the page number. 1 is the firstcontent- the new page contentcompressionLevel- the compressionLevel- Since:
- 2.1.3 (the method already existed without param compressionLevel)
-
setPageContent
public void setPageContent(int pageNum, byte[] content, int compressionLevel, boolean killOldXRefRecursively) Sets the contents of the page.- Parameters:
pageNum- the page number. 1 is the firstcontent- the new page contentcompressionLevel- the compressionLevelkillOldXRefRecursively- if true, old contents will be deeply removed from the pdf (i.e. if it was an array, all its entries will also be removed). Use careful when a content stream may be reused. If false, old contents will not be removed and will stay in the document if not manually deleted.- Since:
- 5.5.7 (the method already existed without param killOldXRefRecursively)
-
decodeBytes
Decode a byte[] applying the filters specified in the provided dictionary using default filter handlers.- Parameters:
b- the bytes to decodestreamDictionary- the dictionary that contains filter information- Returns:
- the decoded bytes
- Throws:
IOException- if there are any problems decoding the bytes- Since:
- 5.0.4
-
decodeBytes
public static byte[] decodeBytes(byte[] b, PdfDictionary streamDictionary, Map<PdfName, FilterHandlers.FilterHandler> filterHandlers) throws IOException Decode a byte[] applying the filters specified in the provided dictionary using the provided filter handlers.- Parameters:
b- the bytes to decodestreamDictionary- the dictionary that contains filter informationfilterHandlers- the map used to look up a handler for each type of filter- Returns:
- the decoded bytes
- Throws:
IOException- if there are any problems decoding the bytes- Since:
- 5.0.4
-
getStreamBytes
public static byte[] getStreamBytes(PRStream stream, RandomAccessFileOrArray file) throws 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:
IOException- on error
-
getStreamBytes
Get the content from a stream applying the required filters.- Parameters:
stream- the stream- Returns:
- the stream content
- Throws:
IOException- on error
-
getStreamBytesRaw
public static byte[] getStreamBytesRaw(PRStream stream, RandomAccessFileOrArray file) throws 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:
IOException- on error
-
getStreamBytesRaw
Get the content from a stream as it is without applying any filter.- 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 long 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 long 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 long getPermissions()Gets the encryption permissions. It can be used directly inPdfWriter.setEncryption().- Returns:
- the encryption permissions
-
is128Key
public boolean is128Key()Returnstrueif the PDF has a 128 bit key encryption.- Returns:
trueif the PDF has a 128 bit key encryption
-
getTrailer
-
getDecrypt
PdfEncryption getDecrypt() -
equalsn
static boolean equalsn(byte[] a1, byte[] a2) -
existsName
-
getFontName
-
getSubsetPrefix
-
shuffleSubsetNames
public int shuffleSubsetNames()Finds all the font subsets and changes the prefixes to some random values.- Returns:
- the number of font subsets altered
-
createFakeFontSubsets
public int createFakeFontSubsets()Finds all the fonts not subset but embedded and marks them as subset.- Returns:
- the number of fonts altered
-
getNameArray
-
getNamedDestination
-
getNamedDestination
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
-
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.- 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
-
removeFields
public void removeFields()Removes all the fields from the document. -
removeAnnotations
public void removeAnnotations()Removes all the annotations and fields from the document. -
getLinks
Retrieves links for a certain page.- Parameters:
page- the page to inspect- Returns:
- a list of links
-
iterateBookmarks
-
makeRemoteNamedDestinationsLocal
public void makeRemoteNamedDestinationsLocal()Replaces remote named links with local destinations that have the same name.- Since:
- 5.0
-
convertNamedDestination
Converts a remote named destination GoToR with a local named destination if there's a corresponding name.- Parameters:
obj- an annotation that needs to be screened for links to external named destinations.names- a map with names of local named destinations- Since:
- iText 5.0
-
consolidateNamedDestinations
public void consolidateNamedDestinations()Replaces all the local named links with the actual destinations. -
replaceNamedDestination
-
duplicatePdfDictionary
protected static PdfDictionary duplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader) -
duplicatePdfObject
-
close
public void close()Closes the reader, and any underlying stream or data source used to create the reader -
removeUnusedNode
-
removeUnusedObjects
public int removeUnusedObjects()Removes all the unreachable objects.- Returns:
- the number of indirect objects removed
-
getAcroFields
Gets a read-only version ofAcroFields.- Returns:
- a read-only version of
AcroFields
-
getJavaScript
Gets the global document JavaScript.- Parameters:
file- the document file- Returns:
- the global document JavaScript
- Throws:
IOException- on error
-
getJavaScript
Gets the global document JavaScript.- Returns:
- the global document JavaScript
- Throws:
IOException- on error
-
selectPages
Selects the pages to keep in the document. The pages are described as ranges. The page ordering can be changed but no page repetitions are allowed. Note that it may be very slow in partial mode.- Parameters:
ranges- the comma separated ranges as described inSequenceList
-
selectPages
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
-
selectPages
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 documentremoveUnused- indicate if to remove unsed objects. @see removeUnusedObjects
-
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:
-
setViewerPreferences
-
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 long 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() -
hasUsageRights
public boolean hasUsageRights()Checks if this PDF has usage rights enabled.- Returns:
trueif usage rights are present;falseotherwise
-
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()- Returns:
- the crypto mode, or -1 of none
-
isMetadataEncrypted
public boolean isMetadataEncrypted()- Returns:
- true if the metadata is encrypted.
-
computeUserPassword
public byte[] computeUserPassword()Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 encryption algorithm.- Returns:
- user password, or null if not a standard encryption handler was used, if standard encryption handler was used with AES256 encryption algorithm, or if ownerPasswordUsed wasn't use to open the document.
-