# PdfStream class

> A PDF stream: a dictionary plus encoded data. Streams are always indirect objects; add new ones with AddObject and refer to the returned reference.

Namespace: [PdfNetStack.Objects](https://www.jadev-corp.com/api/pdfnetstack-objects/)  
Assembly: PdfNetStack.dll  
Package: `PdfNetStack`

A PDF stream: a dictionary plus encoded data. Streams are always indirect objects; add new
ones with [AddObject](https://www.jadev-corp.com/api/pdfnetstack/pdfdocument/#PdfNetStack_PdfDocument_AddObject_PdfNetStack_Objects_PdfObject_) and refer to the returned reference.

```csharp
public sealed class PdfStream : PdfObject
```

**Inheritance**

[object](https://learn.microsoft.com/dotnet/api/system.object) ← 
[PdfObject](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfobject/) ← 
[PdfStream](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfstream/)

## Constructors

### <a id="PdfNetStack_Objects_PdfStream__ctor_PdfNetStack_Objects_PdfDictionary_System_ReadOnlyMemory_System_Byte__"></a> PdfStream\(PdfDictionary, ReadOnlyMemory&lt;byte\>\)

Creates a stream from data already encoded as the dictionary's /Filter says.

```csharp
public PdfStream(PdfDictionary dictionary, ReadOnlyMemory<byte> data)
```

#### Parameters

`dictionary` [PdfDictionary](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfdictionary/)

`data` [ReadOnlyMemory](https://learn.microsoft.com/dotnet/api/system.readonlymemory\-1)<[byte](https://learn.microsoft.com/dotnet/api/system.byte)\>

## Properties

### <a id="PdfNetStack_Objects_PdfStream_Data"></a> Data

Encoded stream bytes, exactly as stored between stream and endstream. For a document
opened from a stream without loading it, the bytes are read from the file on each access
and not kept, until new data is assigned.

```csharp
public ReadOnlyMemory<byte> Data { get; set; }
```

#### Property Value

 [ReadOnlyMemory](https://learn.microsoft.com/dotnet/api/system.readonlymemory\-1)<[byte](https://learn.microsoft.com/dotnet/api/system.byte)\>

### <a id="PdfNetStack_Objects_PdfStream_Dictionary"></a> Dictionary

The stream dictionary. /Length is written on save and need not be kept current.

```csharp
public PdfDictionary Dictionary { get; }
```

#### Property Value

 [PdfDictionary](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfdictionary/)

## Methods

### <a id="PdfNetStack_Objects_PdfStream_FromData_System_ReadOnlySpan_System_Byte__PdfNetStack_Objects_PdfDictionary_System_Boolean_"></a> FromData\(ReadOnlySpan&lt;byte\>, PdfDictionary?, bool\)

Creates a stream from plain data, Flate compressed unless <code class="paramref">compress</code> is
false. /Filter and /DecodeParms of <code class="paramref">dictionary</code> are replaced to match.

```csharp
public static PdfStream FromData(ReadOnlySpan<byte> data, PdfDictionary? dictionary = null, bool compress = true)
```

#### Parameters

`data` [ReadOnlySpan](https://learn.microsoft.com/dotnet/api/system.readonlyspan\-1)<[byte](https://learn.microsoft.com/dotnet/api/system.byte)\>

`dictionary` [PdfDictionary](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfdictionary/)?

`compress` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

#### Returns

 [PdfStream](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfstream/)

## Used in

- [Low level PDF objects in C#](https://www.jadev-corp.com/guides/low-level-objects/)
- [Create PDF/A files in C# and .NET](https://www.jadev-corp.com/guides/pdf-a/)

Source: https://www.jadev-corp.com/pdfnetstack/api/pdfnetstack-objects/pdfstream/
