- java.lang.Object
-
- com.lowagie.text.pdf.PdfReader
-
- All Implemented Interfaces:
PdfViewerPreferences,Closeable,AutoCloseable
- Direct Known Subclasses:
FdfReader
public class PdfReader extends Object implements PdfViewerPreferences, Closeable
Reads a PDF document.- Author:
- Paulo Soares (psoares@consiste.pt), Kazuya Ujihara
-
-
Field Summary
Fields Modifier and Type Field Description protected PRAcroFormacroFormprotected booleanacroFormParsedprotected PdfDictionarycatalogprotected Certificatecertificateprotected KeycertificateKeyprotected StringcertificateKeyProviderprotected booleanconsolidateNamedDestinationsprotected PdfEncryptiondecryptprotected booleanencryptedprotected inteofPosprotected intfreeXrefprotected intlastXrefprotected booleannewXrefTypeprotected Map<Integer,IntHashtable>objStmMarkprotected IntHashtableobjStmToOffsetprotected com.lowagie.text.pdf.PdfReader.PageRefspageRefsprotected byte[]passwordprotected charpdfVersionprotected intpValueprotected booleanrebuiltprotected booleanremoteToLocalNamedDestinationsprotected intrValueprotected booleansharedStreamsprotected List<PdfObject>stringsprotected booleantamperedprotected PRTokenisertokensprotected PdfDictionarytrailerprotected int[]xref
-
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.PdfReader(PdfReader reader)Creates an independent duplicate.PdfReader(RandomAccessFileOrArray raf, byte[] ownerPassword)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(String filename)Reads and parses a PDF document.PdfReader(String filename, byte[] ownerPassword)Reads and parses a PDF document.PdfReader(String filename, Certificate certificate, Key certificateKey, String certificateKeyProvider)Reads and parses a PDF document.PdfReader(URL url)Reads and parses a PDF document.PdfReader(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 preferencestatic byte[]ASCII85Decode(byte[] in)Decodes a stream that has the ASCII85Decode filter.static byte[]ASCIIHexDecode(byte[] in)Decodes a stream that has the ASCIIHexDecode filter.voidclose()Closes the readerbyte[]computeUserPassword()voidconsolidateNamedDestinations()Replaces all the local named links with the actual destinations.static PdfObjectconvertPdfNull(PdfObject obj)If given object is instance ofPdfNull, thennullis returned.intcreateFakeFontSubsets()Finds all the fonts not subset but embedded and marks them as subset.static byte[]decodePredictor(byte[] in, PdfObject dicPar)doubledumpPerc()protected static PdfDictionaryduplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader)protected static PdfObjectduplicatePdfObject(PdfObject original, PdfReader newReader)voideliminateSharedStreams()Eliminates shared streams if they exist.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.RectanglegetBoxSize(int index, String boxName)Gets the box size.PdfDictionarygetCatalog()Returns the document's catalog.intgetCertificationLevel()Gets the certification level for this document.RectanglegetCropBox(int index)Gets the crop box without taking rotation into account.intgetCryptoMode()byte[]getDocumentId()Returns a permanent document identifier extracted from trailer /ID entry, when presentintgetEofPos()Gets the byte address of the %%EOF marker.intgetFileLength()Getter for property fileLength.Map<String,String>getInfo()Returns the content of the document information dictionary as aHashMapofString.StringgetJavaScript()Gets the global document JavaScript.StringgetJavaScript(RandomAccessFileOrArray file)Gets the global document JavaScript.intgetLastXref()Gets the byte address of the last xref table.ArrayList<PdfAnnotation.PdfImportedLink>getLinks(int page)byte[]getMetadata()Gets the XML metadata.HashMap<Object,PdfObject>getNamedDestination()Gets all the named destinations as anHashMap.HashMap<Object,PdfObject>getNamedDestination(boolean keepNames)Gets all the named destinations as anHashMap.HashMapgetNamedDestinationFromNames()Gets the named destinations from the /Dests key in the catalog as anHashMap.HashMap<Object,PdfObject>getNamedDestinationFromNames(boolean keepNames)Gets the named destinations from the /Dests key in the catalog as anHashMap.HashMapgetNamedDestinationFromStrings()Gets the named destinations from the /Names key in the catalog as anHashMap.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)Gets the contents of the page.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.RectanglegetPageSize(int index)Gets the page size without taking rotation into account.RectanglegetPageSize(PdfDictionary page)Gets the page from a page dictionaryRectanglegetPageSizeWithRotation(int index)Gets the page size, taking rotation into account.RectanglegetPageSizeWithRotation(int index, String boxName)Gets the page size, taking rotation into account.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.static PdfObjectgetPdfObject(PdfObject obj, PdfObject parent)static PdfObjectgetPdfObjectNullConverting(PdfObject obj, PdfObject parent)ReturnsgetPdfObject(PdfObject, PdfObject)with appliedconvertPdfNull(PdfObject).PdfObjectgetPdfObjectRelease(int idx)static PdfObjectgetPdfObjectRelease(PdfObject obj)static PdfObjectgetPdfObjectRelease(PdfObject obj, PdfObject parent)Reads aPdfObjectresolving an indirect reference if needed.static PdfObjectgetPdfObjectReleaseNullConverting(PdfObject obj)ReturnsgetPdfObjectRelease(PdfObject)with appliedconvertPdfNull(PdfObject).protected com.lowagie.text.pdf.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.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.PdfDictionarygetTrailer()Gets the trailer dictionaryintgetXrefSize()Gets the number of xref objects.booleanis128Key()Returnstrueif the PDF has a 128 bit key encryption.booleanisAppendable()Getter for property appendable.booleanisEncrypted()Returnstrueif the PDF is encrypted.booleanisHybridXref()Getter for property hybridXref.booleanisMetadataEncrypted()booleanisModificationlowedWithoutOwnerPassword()Checks if an encrypted document may be modified if the owner password was not supplied.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.booleanisOwnerPasswordUsed()Returnstrueif the owner password has been used to open the document.booleanisRebuilt()Checks if the document had errors and was rebuilt.booleanisTampered()Checks if the document was changed.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)static byte[]LZWDecode(byte[] in)Decodes a stream that has the LZWDecode filter.voidmakeRemoteNamedDestinationsLocal()Replaces remote named links with local destinations that have the same name.protected PdfArrayreadArray()protected PdfDictionaryreadDictionary()protected voidreadDocObj()protected voidreadDocObjPartial()protected voidreadObjStm(PRStream stream, IntHashtable map)protected PdfObjectreadOneObjStm(PRStream stream, int idx)protected voidreadPages()protected voidreadPdf()protected voidreadPdfPartial()protected PdfObjectreadPRObject()protected PdfObjectreadSingleObject(int k)protected voidreadXref()protected PdfDictionaryreadXrefSection()protected booleanreadXRefStream(int ptr)protected voidrebuildXref()voidreleaseLastXrefPartial()static voidreleaseLastXrefPartial(PdfObject obj)voidreleasePage(int pageNum)voidremoveAnnotations()Removes all the annotations and fields from the document.voidremoveFields()Removes all the fields from the document.protected voidremoveUnusedNode(PdfObject obj, boolean[] hits)intremoveUnusedObjects()Removes all the unreachable objects.voidremoveUsageRights()Removes any usage rights that this PDF may have.voidresetLastXrefPartial()voidresetReleasePage()voidselectPages(String ranges)Selects the pages to keep in the document.voidselectPages(List<Integer> pagesToKeep)Selects the pages to keep in the document.voidsetAppendable(boolean appendable)Setter for property appendable.voidsetModificationAllowedWithoutOwnerPassword(boolean modificationAllowedWithoutOwnerPassword)Sets whether the document (if encrypted) may be modified even if the owner password was not supplied.voidsetPageContent(int pageNum, byte[] content)Sets the contents of the page.voidsetPageContent(int pageNum, byte[] content, int compressionLevel)Sets the contents of the page.voidsetPermissions(int permissionValue)voidsetTampered(boolean tampered)Sets the tampered state.voidsetViewerPreferences(int preferences)Sets the viewer preferences as the sum of several constants.intshuffleSubsetNames()Finds all the font subsets and changes the prefixes to some random values.
-
-
-
Field Detail
-
tokens
protected PRTokeniser tokens
-
xref
protected int[] xref
-
objStmMark
protected Map<Integer,IntHashtable> objStmMark
-
objStmToOffset
protected IntHashtable objStmToOffset
-
newXrefType
protected boolean newXrefType
-
trailer
protected PdfDictionary trailer
-
catalog
protected PdfDictionary catalog
-
pageRefs
protected com.lowagie.text.pdf.PdfReader.PageRefs pageRefs
-
acroForm
protected PRAcroForm acroForm
-
acroFormParsed
protected boolean acroFormParsed
-
encrypted
protected boolean encrypted
-
rebuilt
protected boolean rebuilt
-
freeXref
protected int freeXref
-
tampered
protected boolean tampered
-
lastXref
protected int lastXref
-
eofPos
protected int eofPos
-
pdfVersion
protected char pdfVersion
-
decrypt
protected PdfEncryption decrypt
-
password
protected byte[] password
-
certificateKey
protected Key certificateKey
-
certificate
protected Certificate certificate
-
certificateKeyProvider
protected String certificateKeyProvider
-
sharedStreams
protected boolean sharedStreams
-
consolidateNamedDestinations
protected boolean consolidateNamedDestinations
-
remoteToLocalNamedDestinations
protected boolean remoteToLocalNamedDestinations
-
rValue
protected int rValue
-
pValue
protected int pValue
-
-
Constructor Detail
-
PdfReader
protected PdfReader()
-
PdfReader
public PdfReader(String filename) throws IOException
Reads and parses a PDF document.- Parameters:
filename- the file name of the document- Throws:
IOException- on error
-
PdfReader
public PdfReader(String filename, byte[] ownerPassword) throws IOException
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
public PdfReader(byte[] pdfIn) throws IOExceptionReads and parses a PDF document.- Parameters:
pdfIn- the byte array with the document- Throws:
IOException- on error
-
PdfReader
public PdfReader(byte[] pdfIn, byte[] ownerPassword) throws IOExceptionReads 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(URL url) throws IOException
Reads and parses a PDF document.- Parameters:
url- the URL of the document- Throws:
IOException- on error
-
PdfReader
public PdfReader(URL url, byte[] ownerPassword) throws IOException
Reads and parses a PDF document.- Parameters:
url- the URL of the documentownerPassword- the password to read the document- Throws:
IOException- on error
-
PdfReader
public PdfReader(InputStream is, byte[] ownerPassword) throws IOException
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
public PdfReader(InputStream is) throws IOException
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
public PdfReader(RandomAccessFileOrArray raf, byte[] ownerPassword) throws IOException
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. The pdf is left open but may be closed at any time withPdfReader.close(), reopen is automatic.- Parameters:
raf- the document locationownerPassword- the password ornullfor no password- Throws:
IOException- on error
-
PdfReader
public PdfReader(PdfReader reader)
Creates an independent duplicate.- Parameters:
reader- thePdfReaderto duplicate
-
-
Method Detail
-
getNormalizedRectangle
public 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
-
getPdfObjectRelease
public static PdfObject getPdfObjectRelease(PdfObject obj)
- Parameters:
obj- an object ofPdfObject- Returns:
- a PdfObject
-
convertPdfNull
public static PdfObject convertPdfNull(PdfObject obj)
If given object is instance ofPdfNull, thennullis returned. The provided object otherwise.- Parameters:
obj- object to convert- Returns:
- provided object or null
-
getPdfObjectReleaseNullConverting
public static PdfObject getPdfObjectReleaseNullConverting(PdfObject obj)
ReturnsgetPdfObjectRelease(PdfObject)with appliedconvertPdfNull(PdfObject).
-
getPdfObject
public static PdfObject getPdfObject(PdfObject obj)
Reads aPdfObjectresolving an indirect reference if needed.- Parameters:
obj- thePdfObjectto read- Returns:
- the resolved
PdfObject
-
getPdfObjectRelease
public 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- parent object- Returns:
- a PdfObject
-
getPdfObject
public static PdfObject getPdfObject(PdfObject obj, PdfObject parent)
- Parameters:
obj- thePdfObjectto readparent- parent object- Returns:
- a PdfObject
-
getPdfObjectNullConverting
public static PdfObject getPdfObjectNullConverting(PdfObject obj, PdfObject parent)
ReturnsgetPdfObject(PdfObject, PdfObject)with appliedconvertPdfNull(PdfObject).
-
releaseLastXrefPartial
public static void releaseLastXrefPartial(PdfObject obj)
- Parameters:
obj- an object ofPdfObject
-
killIndirect
public 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
-
FlateDecode
public static byte[] FlateDecode(byte[] in)
Decodes a stream that has the FlateDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
decodePredictor
public static byte[] decodePredictor(byte[] in, PdfObject dicPar)- Parameters:
in- the input datadicPar- an object ofPdfObject- 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
public static byte[] ASCIIHexDecode(byte[] in)
Decodes a stream that has the ASCIIHexDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
ASCII85Decode
public static byte[] ASCII85Decode(byte[] in)
Decodes a stream that has the ASCII85Decode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
LZWDecode
public static byte[] LZWDecode(byte[] in)
Decodes a stream that has the LZWDecode filter.- Parameters:
in- the input data- Returns:
- the decoded data
-
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
public static byte[] getStreamBytes(PRStream stream) throws IOException
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
public static byte[] getStreamBytesRaw(PRStream stream) throws IOException
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
-
duplicatePdfDictionary
protected static PdfDictionary duplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader)
-
duplicatePdfObject
protected static PdfObject duplicatePdfObject(PdfObject original, PdfReader newReader)
-
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 com.lowagie.text.pdf.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
-
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
public Rectangle getPageSizeWithRotation(PdfDictionary page)
Gets the rotated page from a page dictionary.- Parameters:
page- the page dictionary- Returns:
- the rotated page or null when the page does not exists
-
getPageSizeWithRotation
public Rectangle getPageSizeWithRotation(int index, String boxName)
Gets the page size, taking rotation into account. This is aRectanglewith the value of a an arbitrary box and the /Rotate key.- Parameters:
index- the page number. The first page is 1boxName- of the rotated box. Allowed names are: "crop", "trim", "art", "bleed" and "media".- Returns:
- a
Rectangleor null if the page does not exist
-
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
public Rectangle getPageSize(PdfDictionary page)
Gets the page from a page dictionary- Parameters:
page- the page dictionary- Returns:
- the page
-
getCropBox
public Rectangle getCropBox(int index)
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
public Rectangle getBoxSize(int index, 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 Map<String,String> getInfo()
Returns the content of the document information dictionary as aHashMapofString.- Returns:
- content of the document information dictionary
-
readPdf
protected void readPdf() throws IOException- Throws:
IOException
-
readPdfPartial
protected void readPdfPartial() throws IOException- Throws:
IOException
-
getPdfObjectRelease
public PdfObject getPdfObjectRelease(int idx)
- Parameters:
idx- index- Returns:
- a PdfObject
-
getPdfObject
public PdfObject getPdfObject(int idx)
- Parameters:
idx- index- Returns:
- aPdfObject
-
resetLastXrefPartial
public void resetLastXrefPartial()
-
releaseLastXrefPartial
public void releaseLastXrefPartial()
-
addPdfObject
public PRIndirectReference addPdfObject(PdfObject obj)
- Parameters:
obj- an object ofPdfObject- Returns:
- an indirect reference
-
readPages
protected void readPages() throws IOException- Throws:
IOException
-
readDocObjPartial
protected void readDocObjPartial() throws IOException- Throws:
IOException
-
readSingleObject
protected PdfObject readSingleObject(int k) throws IOException
- Throws:
IOException
-
readOneObjStm
protected PdfObject readOneObjStm(PRStream stream, int idx) throws IOException
- Throws:
IOException
-
dumpPerc
public double dumpPerc()
- Returns:
- the percentage of the cross reference table that has been read
-
readDocObj
protected void readDocObj() throws IOException- Throws:
IOException
-
readObjStm
protected void readObjStm(PRStream stream, IntHashtable map) throws IOException
- Throws:
IOException
-
readXref
protected void readXref() throws IOException- Throws:
IOException
-
readXrefSection
protected PdfDictionary readXrefSection() throws IOException
- Throws:
IOException
-
readXRefStream
protected boolean readXRefStream(int ptr) throws IOException- Throws:
IOException
-
rebuildXref
protected void rebuildXref() throws IOException- Throws:
IOException
-
readDictionary
protected PdfDictionary readDictionary() throws IOException
- Throws:
IOException
-
readArray
protected PdfArray readArray() throws IOException
- Throws:
IOException
-
readPRObject
protected PdfObject readPRObject() throws IOException
- Throws:
IOException
-
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 or null when the page does not exist
-
getPageNRelease
public PdfDictionary getPageNRelease(int pageNum)
- Parameters:
pageNum- page number- Returns:
- a Dictionary object
-
releasePage
public void releasePage(int pageNum)
- Parameters:
pageNum- page number
-
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 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:
IOException- on error
-
getPageContent
public byte[] getPageContent(int pageNum) throws IOExceptionGets the contents of the page.- Parameters:
pageNum- the page number. 1 is the first- Returns:
- the content
- Throws:
IOException- on error
-
killXref
protected void killXref(PdfObject obj)
-
setPageContent
public void setPageContent(int pageNum, byte[] content)Sets the contents of the page.- Parameters:
content- the new page contentpageNum- the page number. 1 is the first
-
setPageContent
public 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 firstcompressionLevel- compression level- Since:
- 2.1.3 (the method already existed without param compressionLevel)
-
eliminateSharedStreams
public 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 IOExceptionGets 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
-
isOwnerPasswordUsed
public boolean isOwnerPasswordUsed()
Returnstrueif the owner password has been used to open the document.- Returns:
trueif the owner password has been used to open the document.
-
getPermissions
public int getPermissions()
Gets the encryption permissions. It can be used directly inPdfWriter.setEncryption().- Returns:
- the encryption permissions
-
setPermissions
public void setPermissions(int permissionValue)
-
is128Key
public boolean is128Key()
Returnstrueif the PDF has a 128 bit key encryption.- Returns:
trueif the PDF has a 128 bit key encryption
-
getTrailer
public PdfDictionary getTrailer()
Gets the trailer dictionary- Returns:
- the trailer dictionary
-
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
-
getNamedDestination
public HashMap<Object,PdfObject> 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
public HashMap<Object,PdfObject> 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 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
public HashMap<Object,PdfObject> 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 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
-
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
public ArrayList<PdfAnnotation.PdfImportedLink> getLinks(int page)
-
makeRemoteNamedDestinationsLocal
public void makeRemoteNamedDestinationsLocal()
Replaces remote named links with local destinations that have the same name.- Since:
- 5.0
-
consolidateNamedDestinations
public void consolidateNamedDestinations()
Replaces all the local named links with the actual destinations.
-
close
public void close()
Closes the reader- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
removeUnusedNode
protected void removeUnusedNode(PdfObject obj, boolean[] hits)
-
removeUnusedObjects
public 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
public String getJavaScript(RandomAccessFileOrArray file) throws IOException
Gets the global document JavaScript.- Parameters:
file- the document file- Returns:
- the global document JavaScript
- Throws:
IOException- on error
-
getJavaScript
public String getJavaScript() throws IOException
Gets the global document JavaScript.- Returns:
- the global document JavaScript
- Throws:
IOException- on error
-
selectPages
public void selectPages(String ranges)
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
public void selectPages(List<Integer> 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.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject)
-
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
-
isModificationlowedWithoutOwnerPassword
public boolean isModificationlowedWithoutOwnerPassword()
Checks if an encrypted document may be modified if the owner password was not supplied. If the document is not encrypted, the setting has no effect.- Returns:
trueif the document may be modified even if the owner password was not suppliedfalseotherwise
-
setModificationAllowedWithoutOwnerPassword
public void setModificationAllowedWithoutOwnerPassword(boolean modificationAllowedWithoutOwnerPassword)
Sets whether the document (if encrypted) may be modified even if the owner password was not supplied. If this is set tofalsean exception will be thrown when attempting to access the Document if the owner password was not supplied (for encrypted documents.)- Parameters:
modificationAllowedWithoutOwnerPassword- the modificationAllowedWithoutOwnerPassword state.
-
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 or the modificationAllowedWithoutOwnerPassword flag is set,falseotherwise.
-
getCryptoMode
public int getCryptoMode()
-
isMetadataEncrypted
public boolean isMetadataEncrypted()
-
computeUserPassword
public byte[] computeUserPassword()
-
getDocumentId
public byte[] getDocumentId()
Returns a permanent document identifier extracted from trailer /ID entry, when present- Returns:
- byte array representing the document permanent identifier
-
-