PdfStream Class

A stream: a dictionary and a sequence of bytes (ISO 32000-2, 7.3.8). It is mutable and not thread-safe.

public sealed class PdfStream : PdfObject

Remarks

The data is kept encoded, as the /Filter and /DecodeParms entries of the dictionary describe it. PdfStream.GetDecodedData applies the filters. PdfStream.SetData stores data without filter: the writer compresses it when PdfSaveOptions.CompressStreams is set. The writer always writes the /Length entry from the data.

A stream is always an indirect object: add it to PdfIndirectObjectCollection and refer to it with the reference.

Inheritance
PdfObject PdfStream

Constructors

NameDescription
PdfStream()Initializes a new instance of the PdfStream class with an empty dictionary and no data.
PdfStream(PdfDictionary)Initializes a new instance of the PdfStream class.
PdfStream(PdfDictionary, ReadOnlySpan<byte>)Initializes a new instance of the PdfStream class with data without filter.

PdfStream overloads

PdfStream()

PdfStream.cs

Initializes a new instance of the PdfStream class with an empty dictionary and no data.

public PdfStream()

PdfStream(PdfDictionary)

PdfStream.cs

Initializes a new instance of the PdfStream class.

public PdfStream(PdfDictionary dictionary)
Parameters
dictionary PdfDictionary
The dictionary of the stream.

PdfStream(PdfDictionary, ReadOnlySpan<byte>)

PdfStream.cs

Initializes a new instance of the PdfStream class with data without filter.

public PdfStream(PdfDictionary dictionary, ReadOnlySpan<byte> data)
Parameters
dictionary PdfDictionary
The dictionary of the stream.
data ReadOnlySpan<byte>
The data.

Properties

NameDescription
DictionaryGets the dictionary of the stream.
EncodedDataGets the data of the stream, encoded with its filters.
FiltersGets the names of the filters of the stream, in the order they are applied to decode it.
KindGets the kind of the object.

Dictionary

PdfStream.cs

Gets the dictionary of the stream.

public PdfDictionary Dictionary { get; }

Property value

PdfDictionary

EncodedData

PdfStream.cs

Gets the data of the stream, encoded with its filters.

public ReadOnlyMemory<byte> EncodedData { get; }

Property value

ReadOnlyMemory<byte>

Gets the names of the filters of the stream, in the order they are applied to decode it.

public IReadOnlyList<PdfName> Filters { get; }

Gets the kind of the object.

public override PdfObjectKind Kind { get; }

Property value

PdfObjectKind

Methods

NameDescription
GetDecodedData()Decodes the data with the filters of the stream.
SetData(ReadOnlySpan<byte>)Replaces the data with data without filter, and removes the /Filter and /DecodeParms entries.
SetEncodedData(ReadOnlySpan<byte>)Replaces the data with data already encoded with the filters the dictionary declares.
SetEncodedData(ReadOnlySpan<byte>, PdfName, PdfDictionary?)Replaces the data with data encoded with one filter, and sets the /Filter and /DecodeParms entries.

GetDecodedData()

PdfStream.cs

Decodes the data with the filters of the stream.

public byte[] GetDecodedData()

Returns

byte[] The decoded data. For an image filter (DCTDecode, JPXDecode), the samples of the image.

Exceptions

InvalidPdfContentException
The data is not valid for a filter, or a filter is unknown.
UnsupportedPdfFeatureException
A filter is not supported.
PdfResourceLimitException
The decoded data exceeds PdfReadOptions.MaxDecodedStreamLength.

SetData(ReadOnlySpan<byte>)

PdfStream.cs

Replaces the data with data without filter, and removes the /Filter and /DecodeParms entries.

public void SetData(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>
The data.

SetEncodedData overloads

SetEncodedData(ReadOnlySpan<byte>)

PdfStream.cs

Replaces the data with data already encoded with the filters the dictionary declares.

public void SetEncodedData(ReadOnlySpan<byte> data)
Parameters
data ReadOnlySpan<byte>
The encoded data.

SetEncodedData(ReadOnlySpan<byte>, PdfName, PdfDictionary?)

PdfStream.cs

Replaces the data with data encoded with one filter, and sets the /Filter and /DecodeParms entries.

public void SetEncodedData(ReadOnlySpan<byte> data, PdfName filter, PdfDictionary? decodeParameters = null)
Parameters
data ReadOnlySpan<byte>
The encoded data.
filter PdfName
The filter that decodes the data, such as FlateDecode or DCTDecode.
decodeParameters PdfDictionary?
The parameters of the filter, or null.