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 : PdfObjectRemarks
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
PdfObjectPdfStream
Constructors
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the PdfStream class with an empty dictionary and no data.
public PdfStream()PdfStream(PdfDictionary)
PdfStream.csInitializes a new instance of the PdfStream class.
public PdfStream(PdfDictionary dictionary)Parameters
dictionaryPdfDictionary- The dictionary of the stream.
PdfStream(PdfDictionary, ReadOnlySpan<byte>)
PdfStream.csInitializes a new instance of the PdfStream class with data without filter.
public PdfStream(PdfDictionary dictionary, ReadOnlySpan<byte> data)Parameters
dictionaryPdfDictionary- The dictionary of the stream.
dataReadOnlySpan<byte>- The data.
Properties
| Name | Description |
|---|---|
| Dictionary | Gets the dictionary of the stream. |
| EncodedData | Gets the data of the stream, encoded with its filters. |
| Filters | Gets the names of the filters of the stream, in the order they are applied to decode it. |
| Kind | Gets the kind of the object. |
Dictionary
PdfStream.csEncodedData
PdfStream.csGets the data of the stream, encoded with its filters.
public ReadOnlyMemory<byte> EncodedData { get; }Property value
Filters
PdfStream.csGets the names of the filters of the stream, in the order they are applied to decode it.
public IReadOnlyList<PdfName> Filters { get; }Property value
Kind
PdfStream.csMethods
| Name | Description |
|---|---|
| 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.csDecodes 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.csReplaces the data with data without filter, and removes the /Filter and /DecodeParms entries.
public void SetData(ReadOnlySpan<byte> data)Parameters
dataReadOnlySpan<byte>- The data.
SetEncodedData overloads
SetEncodedData(ReadOnlySpan<byte>)
PdfStream.csReplaces the data with data already encoded with the filters the dictionary declares.
public void SetEncodedData(ReadOnlySpan<byte> data)Parameters
dataReadOnlySpan<byte>- The encoded data.
SetEncodedData(ReadOnlySpan<byte>, PdfName, PdfDictionary?)
PdfStream.csReplaces 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
dataReadOnlySpan<byte>- The encoded data.
filterPdfName- The filter that decodes the data, such as
FlateDecodeorDCTDecode. decodeParametersPdfDictionary?- The parameters of the filter, or
null.