Table of Contents

Class PdfReader

Namespace
iText.Kernel.Pdf
Assembly
itext.kernel.dll

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 FileInfo

the File containing the document.

PdfReader(FileInfo, ReaderProperties)

Reads and parses a PDF document.

public PdfReader(FileInfo file, ReaderProperties properties)

Parameters

file FileInfo

the file of the document

properties ReaderProperties

properties of the created reader

PdfReader(Stream)

Reads and parses a PDF document.

public PdfReader(Stream @is)

Parameters

is Stream

the 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 Stream

the 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 ReaderProperties

properties of the created reader

PdfReader(string)

Reads and parses a PDF document.

public PdfReader(string filename)

Parameters

filename string

the file name of the document

PdfReader(string, ReaderProperties)

Reads and parses a PDF document.

public PdfReader(string filename, ReaderProperties properties)

Parameters

filename string

the file name of the document

properties ReaderProperties

properties of the created reader

PdfReader(IRandomAccessSource, ReaderProperties)

Constructs a new PdfReader.

public PdfReader(IRandomAccessSource byteSource, ReaderProperties properties)

Parameters

byteSource IRandomAccessSource

source of bytes for the reader

properties ReaderProperties

properties 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

PdfReader.StrictnessLevel

correctStreamLength

protected static bool correctStreamLength

Field Value

bool

decrypt

protected PdfEncryption decrypt

Field Value

PdfEncryption

encrypted

protected bool encrypted

Field Value

bool

eofPos

protected long eofPos

Field Value

long

fixedXref

protected bool fixedXref

Field Value

bool

headerPdfVersion

protected PdfVersion headerPdfVersion

Field Value

PdfVersion

hybridXref

protected bool hybridXref

Field Value

bool

lastXref

protected long lastXref

Field Value

long

pdfAConformanceLevel

protected PdfAConformanceLevel pdfAConformanceLevel

Field Value

PdfAConformanceLevel

pdfDocument

protected PdfDocument pdfDocument

Field Value

PdfDocument

properties

protected ReaderProperties properties

Field Value

ReaderProperties

rebuiltXref

protected bool rebuiltXref

Field Value

bool

tokens

protected PdfTokenizer tokens

Field Value

PdfTokenizer

trailer

protected PdfDictionary trailer

Field Value

PdfDictionary

xrefStm

protected bool xrefStm

Field Value

bool

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 PdfDictionary

the 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 PdfDictionary

the 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

PdfNumber

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

bool

true, if Close() method will close input stream, otherwise false.

IsEncrypted()

Checks if the PdfDocument read with this PdfReader is encrypted.

public virtual bool IsEncrypted()

Returns

bool

true is the document is encrypted, otherwise false.

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

PdfArray

ReadDictionary(bool)

protected virtual PdfDictionary ReadDictionary(bool objStm)

Parameters

objStm bool

Returns

PdfDictionary

ReadObject(bool)

protected virtual PdfObject ReadObject(bool readAsDirect)

Parameters

readAsDirect bool

Returns

PdfObject

ReadObject(bool, bool)

protected virtual PdfObject ReadObject(bool readAsDirect, bool objStm)

Parameters

readAsDirect bool
objStm bool

Returns

PdfObject

ReadObject(PdfIndirectReference)

protected virtual PdfObject ReadObject(PdfIndirectReference reference)

Parameters

reference PdfIndirectReference

Returns

PdfObject

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

PdfName

ReadReference(bool)

protected virtual PdfObject ReadReference(bool readAsDirect)

Parameters

readAsDirect bool

Returns

PdfObject

ReadStream(PdfStream, bool)

Reads, decrypts and optionally decodes stream bytes into MemoryStream.

public virtual Stream ReadStream(PdfStream stream, bool decode)

Parameters

stream PdfStream

a PdfStream stream instance to be read

decode bool

true if to get decoded stream, false if to leave it originally encoded.

Returns

Stream

InputStream or null if reading was failed.

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 PdfStream

a PdfStream stream instance to be read and optionally decoded.

decode bool

true 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

stream PdfStream

a PdfStream stream instance to be read

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

PdfDictionary

ReadXrefStream(long)

protected virtual bool ReadXrefStream(long ptr)

Parameters

ptr long

Returns

bool

RebuildXref()

protected virtual void RebuildXref()

SetCloseStream(bool)

Sets whether Close() method shall close input stream.

public virtual void SetCloseStream(bool closeStream)

Parameters

closeStream bool

true, if Close() method shall close input stream, otherwise false.

SetMemorySavingMode(bool)

Defines if memory saving mode is enabled.

public virtual PdfReader SetMemorySavingMode(bool memorySavingMode)

Parameters

memorySavingMode bool

true to enable memory saving mode, false to disable it.

Returns

PdfReader

this PdfReader instance.

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.StrictnessLevel

the PdfReader.StrictnessLevel to set

Returns

PdfReader

this PdfReader instance

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 bool

true to enable unethicalReading, false to disable it. By default unethicalReading is disabled.

Returns

PdfReader

this PdfReader instance.