Skip to main content

Class PdfStreamDecodingExtensions

Namespace: AdCodicem.Pdf.Objects
Assembly: AdCodicem.Pdf.dll

Decoding of stream data.

public static class PdfStreamDecodingExtensions

Inheritance​

object ← PdfStreamDecodingExtensions

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods​

Decode(PdfStream, PdfDiagnostics?)​

Applies the stream's filters and returns the decoded data.

public static ReadOnlyMemory<byte> Decode(this PdfStream stream, PdfDiagnostics? diagnostics = null)

Parameters​

stream PdfStream

The stream to decode.

diagnostics PdfDiagnostics?

Receives anomalies met while decoding. When none are supplied, a stream read from a document reports them in the document's own PdfDocument.Diagnostics, and one built in memory reports nothing.

Returns​

ReadOnlyMemory<byte>

Remarks​

Decoding stops at an image filter: a stream encoded with DCTDecode comes back as the JPEG it already is, rather than as pixels nobody asked for.

Data that is damaged decodes as far as it can, and what decoded is kept: a Flate stream that lost its tail or turned corrupt, or an LZW stream that uses a code it has not defined, comes back as what came before, reported as [PdfDiagnosticCodes.FilterFailed](AdCodicem.Pdf.Diagnostics.PdfDiagnosticCodes#AdCodicem_Pdf_Diagnostics_PdfDiagnosticCodes_FilterFailed). A Flate stream that decodes to its end but whose zlib checksum disagrees comes back whole, reported as [PdfDiagnosticCodes.FilterChecksumMismatch](AdCodicem.Pdf.Diagnostics.PdfDiagnosticCodes#AdCodicem_Pdf_Diagnostics_PdfDiagnosticCodes_FilterChecksumMismatch), since some of it may be wrong. Data that nothing could decode comes back encoded, reported as [PdfDiagnosticCodes.FilterFailed](AdCodicem.Pdf.Diagnostics.PdfDiagnosticCodes#AdCodicem_Pdf_Diagnostics_PdfDiagnosticCodes_FilterFailed). Decoding stops at a filter the library does not recognize: the data comes back as the filters before it decoded it, reported as [PdfDiagnosticCodes.FilterUnsupported](AdCodicem.Pdf.Diagnostics.PdfDiagnosticCodes#AdCodicem_Pdf_Diagnostics_PdfDiagnosticCodes_FilterUnsupported), and the filters after it are not tried on data they could not read. A /Filter entry that is neither a name nor an array leaves the data as it found it, reported the same way.

A stream read from a document decodes under that document's [PdfReaderOptions.Limits](AdCodicem.Pdf.Documents.PdfReaderOptions#AdCodicem_Pdf_Documents_PdfReaderOptions_Limits); one built in memory, under [PdfReaderLimits.Default](AdCodicem.Pdf.Documents.PdfReaderLimits#AdCodicem_Pdf_Documents_PdfReaderLimits_Default). Data that decodes past the bound is kept up to it and reported as [PdfDiagnosticCodes.LimitDecodedStream](AdCodicem.Pdf.Diagnostics.PdfDiagnosticCodes#AdCodicem_Pdf_Diagnostics_PdfDiagnosticCodes_LimitDecodedStream).

Exceptions​

PdfLimitExceededException

The data decodes past its document's bound, and the document was opened with PdfReaderOptions.ThrowOnLimit.

HasImageFilter(PdfStream)​

Determines whether the stream's data is an encoded image that PdfStreamDecodingExtensions.Decode(PdfStream, PdfDiagnostics?) leaves alone.

public static bool HasImageFilter(this PdfStream stream)

Parameters​

stream PdfStream

Returns​

bool