Class PdfReader
Reads a PDF document.
public class PdfReader : IDisposable
- Inheritance
-
PdfReader
- Implements
- Inherited Members
Constructors
PdfReader(FileInfo)
Reads and parses a PDF document.
public PdfReader(FileInfo file)
Parameters
file
FileInfothe
File
containing the document.
PdfReader(FileInfo, ReaderProperties)
Reads and parses a PDF document.
public PdfReader(FileInfo file, ReaderProperties properties)
Parameters
file
FileInfothe file of the document
properties
ReaderPropertiesproperties of the created reader
PdfReader(Stream)
Reads and parses a PDF document.
public PdfReader(Stream @is)
Parameters
is
Streamthe
InputStream
containing the document. If the inputStream is an instance of RASInputStream then the IRandomAccessSource would be extracted. Otherwise the stream is read to the end but is not closed.
PdfReader(Stream, ReaderProperties)
Reads and parses a PDF document.
public PdfReader(Stream @is, ReaderProperties properties)
Parameters
is
Streamthe
InputStream
containing the document. If the inputStream is an instance of RASInputStream then the IRandomAccessSource would be extracted. Otherwise the stream is read to the end but is not closed.properties
ReaderPropertiesproperties of the created reader
PdfReader(string)
Reads and parses a PDF document.
public PdfReader(string filename)
Parameters
filename
stringthe file name of the document
PdfReader(string, ReaderProperties)
Reads and parses a PDF document.
public PdfReader(string filename, ReaderProperties properties)
Parameters
filename
stringthe file name of the document
properties
ReaderPropertiesproperties of the created reader
PdfReader(IRandomAccessSource, ReaderProperties)
Constructs a new PdfReader.
public PdfReader(IRandomAccessSource byteSource, ReaderProperties properties)
Parameters
byteSource
IRandomAccessSourcesource of bytes for the reader
properties
ReaderPropertiesproperties of the created reader
Fields
DEFAULT_STRICTNESS_LEVEL
The default PdfReader.StrictnessLevel to be used.
public static readonly PdfReader.StrictnessLevel DEFAULT_STRICTNESS_LEVEL
Field Value
correctStreamLength
protected static bool correctStreamLength
Field Value
decrypt
protected PdfEncryption decrypt
Field Value
encrypted
protected bool encrypted
Field Value
eofPos
protected long eofPos
Field Value
fixedXref
protected bool fixedXref
Field Value
headerPdfVersion
protected PdfVersion headerPdfVersion
Field Value
hybridXref
protected bool hybridXref
Field Value
lastXref
protected long lastXref
Field Value
pdfAConformanceLevel
protected PdfAConformanceLevel pdfAConformanceLevel
Field Value
pdfDocument
protected PdfDocument pdfDocument
Field Value
properties
protected ReaderProperties properties
Field Value
rebuiltXref
protected bool rebuiltXref
Field Value
tokens
protected PdfTokenizer tokens
Field Value
trailer
protected PdfDictionary trailer
Field Value
xrefStm
protected bool xrefStm
Field Value
Methods
Close()
Close PdfTokenizer.
public virtual void Close()
ComputeUserPassword()
Computes user password if standard encryption handler is used with Standard40, Standard128 or AES128 encryption algorithm.
public virtual byte[] ComputeUserPassword()
Returns
- byte[]
user password, or null if not a standard encryption handler was used or if ownerPasswordUsed wasn't use to open the document.
DecodeBytes(byte[], PdfDictionary)
Decode bytes applying the filters specified in the provided dictionary using default filter handlers.
public static byte[] DecodeBytes(byte[] b, PdfDictionary streamDictionary)
Parameters
b
byte[]the bytes to decode
streamDictionary
PdfDictionarythe dictionary that contains filter information
Returns
- byte[]
the decoded bytes
DecodeBytes(byte[], PdfDictionary, IDictionary<PdfName, IFilterHandler>)
Decode a byte[] applying the filters specified in the provided dictionary using the provided filter handlers.
public static byte[] DecodeBytes(byte[] b, PdfDictionary streamDictionary, IDictionary<PdfName, IFilterHandler> filterHandlers)
Parameters
b
byte[]the bytes to decode
streamDictionary
PdfDictionarythe dictionary that contains filter information
filterHandlers
IDictionary<PdfName, IFilterHandler>the map used to look up a handler for each type of filter
Returns
- byte[]
the decoded bytes
FixXref()
protected virtual void FixXref()
GetCryptoMode()
Gets encryption algorithm and access permissions.
public virtual int GetCryptoMode()
Returns
- int
int
value corresponding to a certain type of encryption.
- See Also
GetFileLength()
Provides the size of the opened file.
public virtual long GetFileLength()
Returns
- long
The size of the opened file.
GetLastXref()
Gets position of the last Cross-Reference table.
public virtual long GetLastXref()
Returns
- long
-1 if Cross-Reference table has rebuilt, otherwise position of the last Cross-Reference table.
GetModifiedFileId()
Gets modified file ID, the second element in ID key of trailer.
public virtual byte[] GetModifiedFileId()
Returns
- byte[]
byte array represents modified file ID.
Remarks
Gets modified file ID, the second element in ID key of trailer. If the size of ID array does not equal 2, an empty array will be returned.
The returned value reflects the value that was written in opened document. If document is modified, the ultimate document id can be retrieved from GetModifiedDocumentId().- See Also
GetOriginalFileId()
Gets original file ID, the first element in ID key of trailer.
public virtual byte[] GetOriginalFileId()
Returns
- byte[]
byte array represents original file ID.
Remarks
Gets original file ID, the first element in ID key of trailer. If the size of ID array does not equal 2, an empty array will be returned.
The returned value reflects the value that was written in opened document. If document is modified, the ultimate document id can be retrieved from GetOriginalDocumentId().- See Also
GetPdfAConformanceLevel()
Gets the declared PDF/A conformance level of the source document that is being read.
public virtual PdfAConformanceLevel GetPdfAConformanceLevel()
Returns
- PdfAConformanceLevel
conformance level of the source document, or null if no PDF/A conformance level information is specified.
Remarks
Gets the declared PDF/A conformance level of the source document that is being read. Note that this information is provided via XMP metadata and is not verified by iText. pdfAConformanceLevel is lazy initialized. It will be initialized during the first call of this method.
GetPermissions()
Gets the encryption permissions.
public virtual long GetPermissions()
Returns
- long
the encryption permissions, an unsigned 32-bit quantity.
Remarks
Gets the encryption permissions. It can be used directly in SetStandardEncryption(byte[], byte[], int, int). See ISO 32000-1, Table 22 for more details.
GetSafeFile()
Gets a new file instance of the original PDF document.
public virtual RandomAccessFileOrArray GetSafeFile()
Returns
- RandomAccessFileOrArray
a new file instance of the original PDF document
GetStrictnessLevel()
Get the current PdfReader.StrictnessLevel of the reader.
public virtual PdfReader.StrictnessLevel GetStrictnessLevel()
Returns
- PdfReader.StrictnessLevel
the current PdfReader.StrictnessLevel
GetXrefPrev(PdfObject)
protected virtual PdfNumber GetXrefPrev(PdfObject prevObjectToCheck)
Parameters
prevObjectToCheck
PdfObject
Returns
HasFixedXref()
If any exception generated while reading PdfObject, PdfReader will try to fix offsets of all objects.
public virtual bool HasFixedXref()
Returns
- bool
true, if PdfReader fixed offsets of PdfObjects.
Remarks
If any exception generated while reading PdfObject, PdfReader will try to fix offsets of all objects.
This method's returned value might change over time, because PdfObjects reading can be postponed even up to document closing.HasHybridXref()
Some documents contain hybrid XRef, for more information see "7.5.8.4 Compatibility with Applications That Do Not Support Compressed Reference Streams" in PDF 32000-1:2008 spec.
public virtual bool HasHybridXref()
Returns
- bool
true, if the document has hybrid Cross-Reference section.
HasRebuiltXref()
If any exception generated while reading XRef section, PdfReader will try to rebuild it.
public virtual bool HasRebuiltXref()
Returns
- bool
true, if PdfReader rebuilt Cross-Reference section.
HasXrefStm()
Indicates whether the document has Cross-Reference Streams.
public virtual bool HasXrefStm()
Returns
- bool
true, if the document has Cross-Reference Streams.
IsCloseStream()
Gets whether Close() method shall close input stream.
public virtual bool IsCloseStream()
Returns
IsEncrypted()
Checks if the PdfDocument read with this PdfReader is encrypted.
public virtual bool IsEncrypted()
Returns
IsOpenedWithFullPermission()
Checks if the document was opened with the owner password so that the end application can decide what level of access restrictions to apply.
public virtual bool IsOpenedWithFullPermission()
Returns
- bool
true if the document was opened with the owner password or if it's not encrypted, false if the document was opened with the user password.
Remarks
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 return true.
ReadArray(bool)
protected virtual PdfArray ReadArray(bool objStm)
Parameters
objStm
bool
Returns
ReadDictionary(bool)
protected virtual PdfDictionary ReadDictionary(bool objStm)
Parameters
objStm
bool
Returns
ReadObject(bool)
protected virtual PdfObject ReadObject(bool readAsDirect)
Parameters
readAsDirect
bool
Returns
ReadObject(bool, bool)
protected virtual PdfObject ReadObject(bool readAsDirect, bool objStm)
Parameters
Returns
ReadObject(PdfIndirectReference)
protected virtual PdfObject ReadObject(PdfIndirectReference reference)
Parameters
reference
PdfIndirectReference
Returns
ReadObjectStream(PdfStream)
protected virtual void ReadObjectStream(PdfStream objectStream)
Parameters
objectStream
PdfStream
ReadPdf()
Parses the entire PDF
protected virtual void ReadPdf()
ReadPdfName(bool)
protected virtual PdfName ReadPdfName(bool readAsDirect)
Parameters
readAsDirect
bool
Returns
ReadReference(bool)
protected virtual PdfObject ReadReference(bool readAsDirect)
Parameters
readAsDirect
bool
Returns
ReadStream(PdfStream, bool)
Reads, decrypts and optionally decodes stream bytes into MemoryStream.
public virtual Stream ReadStream(PdfStream stream, bool decode)
Parameters
stream
PdfStreama PdfStream stream instance to be read
decode
booltrue if to get decoded stream, false if to leave it originally encoded.
Returns
Remarks
Reads, decrypts and optionally decodes stream bytes into MemoryStream. User is responsible for closing returned stream.
ReadStreamBytes(PdfStream, bool)
Reads, decrypt and optionally decode stream bytes.
public virtual byte[] ReadStreamBytes(PdfStream stream, bool decode)
Parameters
stream
PdfStreama PdfStream stream instance to be read and optionally decoded.
decode
booltrue if to get decoded stream bytes, false if to leave it originally encoded.
Returns
- byte[]
byte[] array.
Remarks
Reads, decrypt and optionally decode stream bytes. Note, this method doesn't store actual bytes in any internal structures.
ReadStreamBytesRaw(PdfStream)
Reads and decrypt stream bytes.
public virtual byte[] ReadStreamBytesRaw(PdfStream stream)
Parameters
Returns
- byte[]
byte[] array.
Remarks
Reads and decrypt stream bytes. Note, this method doesn't store actual bytes in any internal structures.
ReadXref()
protected virtual void ReadXref()
ReadXrefSection()
protected virtual PdfDictionary ReadXrefSection()
Returns
ReadXrefStream(long)
protected virtual bool ReadXrefStream(long ptr)
Parameters
ptr
long
Returns
RebuildXref()
protected virtual void RebuildXref()
SetCloseStream(bool)
Sets whether Close() method shall close input stream.
public virtual void SetCloseStream(bool closeStream)
Parameters
SetMemorySavingMode(bool)
Defines if memory saving mode is enabled.
public virtual PdfReader SetMemorySavingMode(bool memorySavingMode)
Parameters
memorySavingMode
booltrue to enable memory saving mode, false to disable it.
Returns
Remarks
Defines if memory saving mode is enabled.
By default memory saving mode is disabled for the sake of time–memory trade-off. If memory saving mode is enabled, document processing might slow down, but reading will be less memory demanding.SetStrictnessLevel(StrictnessLevel)
Set the PdfReader.StrictnessLevel for the reader.
public virtual PdfReader SetStrictnessLevel(PdfReader.StrictnessLevel strictnessLevel)
Parameters
strictnessLevel
PdfReader.StrictnessLevelthe PdfReader.StrictnessLevel to set
Returns
Remarks
Set the PdfReader.StrictnessLevel for the reader. If the argument is null , then the DEFAULT_STRICTNESS_LEVEL will be used.
SetUnethicalReading(bool)
The iText is not responsible if you decide to change the value of this parameter.
public virtual PdfReader SetUnethicalReading(bool unethicalReading)
Parameters
unethicalReading
booltrue to enable unethicalReading, false to disable it. By default unethicalReading is disabled.