# PDFStream Class

> Represents a stream of data within a PDF document.

- Product: Adobe PDF Library 21
- Language: Modern C++
- Version: 21.4.0
- HTML page: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFStream
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class PDFStream : PDFObject
```

**Namespace:** `datalogics_interface`

**Inherits from:** [`PDFObject`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)

## Description

Represents a stream of data within a PDF document.

All objects in a PDF document are built from a collection of simpler objects that represent fundamental datatypes like numbers, strings and arrays.

PDFObject and its subclasses allow direct access and manipulation of these simple objects. Some subclasses represent single data elements (e.g. PDFInteger represents a single integer value); other subclasses represent a collection of PDFObjects (e.g. PDFArray is an indexed array of data elements).

A PDFStream represents a stream of unsigned bytes, and may be inserted into any collection object. It includes a dictionary that describes how the data in the stream is encoded and other useful information about the stream. A PDFStream is always an indirect object.

PDFStreams can be encoded using built-in filters. These filters include compression schemes for most popular image formats, and text encoding translators to permit safe transmission of the document over the Internet. The data in a PDFStream will be automatically encoded when it is created; the user can read either the encoded (raw) or decoded (filtered) data.

PDFStreams can be used for any large collection of data that need not be read into memory all at once, including image data, multimedia data or XML markup.

**Referenced by:** [`Form`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Form.md), [`ICCBasedColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ICCBasedColorSpace.md), [`PostScript`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PostScript.md)

**Uses types:** [`PDFDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md), [`PDFObjectType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PDFObjectType.md)

## Constructors

### PDFStream

```cpp
datalogics_interface::PDFStream::PDFStream(std::istream &input, Document &doc)
```

*constructor*

**Parameters**

- `input` (`std::istream &`)
- `doc` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md))

Create a PDFStream from an input stream in the given document. The stream data is read during construction.

### PDFStream

```cpp
datalogics_interface::PDFStream::PDFStream(std::istream &input, Document &doc, PDFDict &encoding_dict, PDFArray &encoding_params)
```

*constructor*

**Parameters**

- `input` (`std::istream &`)
- `doc` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md))
- `encoding_dict` ([`PDFDict &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md))
- `encoding_params` ([`PDFArray &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFArray.md))

Create a PDFStream from an input stream with encoding parameters. encoding_dict and encoding_params control compression/filters.

## Methods

### get_dict

```cpp
std::unique_ptr< PDFDict > datalogics_interface::PDFStream::get_dict() const
```

**Returns:** [`std::unique_ptr< PDFDict >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md)

The stream's encoding dictionary.

Retrieve the encoding dictionary for this stream (contains /Filter, /DecodeParms, and any other stream metadata). The encoding dictionary for the stream. This includes all required information for decoding the stream, such as filter names and decode parameters.

### get_filtered_bytes

```cpp
std::vector< unsigned char > datalogics_interface::PDFStream::get_filtered_bytes() const
```

**Returns:** `std::vector< unsigned char >`

Read the stream's filtered (decoded) bytes after applying the stream's /Filter and /DecodeParms. Use this for content streams, XMP, images.

### get_generation

```cpp
int datalogics_interface::PDFObject::get_generation() const
```

**Returns:** `int`

The generation number of this indirect object.

The generation number for this object.

Only indirect objects have a generation number.

### get_id

```cpp
int datalogics_interface::PDFObject::get_id() const
```

**Returns:** `int`

The ID number of this indirect object.

The ID number for this object.

Only indirect objects have an ID number.

### get_indirect

```cpp
bool datalogics_interface::PDFObject::get_indirect() const
```

**Returns:** `bool`

true if this object is indirect, false if it is direct.

Indicates if this object is indirect or direct.

### get_length

```cpp
long datalogics_interface::PDFStream::get_length() const
```

**Returns:** `long`

The length of the encoded (raw) stream data.

The encoded length of the stream in bytes.

### get_raw_bytes

```cpp
std::vector< unsigned char > datalogics_interface::PDFStream::get_raw_bytes() const
```

**Returns:** `std::vector< unsigned char >`

Read the stream's raw (encoded, still compressed) bytes — what is actually stored in the PDF file. Use this for signature/XRef work where you need the on-disk bytes.

### get_type

```cpp
PDFObjectType datalogics_interface::PDFObject::get_type() const
```

**Returns:** [`PDFObjectType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PDFObjectType.md)

The underlying Cos type of this object. Prefer this over dynamic_cast/try_as chains in hot paths.

### operator!=

```cpp
bool datalogics_interface::PDFObject::operator!=(const PDFObject &other) const
```

**Parameters**

- `other` ([`const PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md))

**Returns:** `bool`

true if `other` is not equal to this.

Inequality.

### operator==

```cpp
bool datalogics_interface::PDFObject::operator==(const PDFObject &other) const
```

**Parameters**

- `other` ([`const PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)): The other PDFObject to compare against.

**Returns:** `bool`

true if the two objects are equal, false otherwise.

Compare if two objects are equal.

### to_string

```cpp
std::string datalogics_interface::PDFObject::to_string() const
```

**Returns:** `std::string`

A string describing this PDFObject.

Returns a string representation of this PDFObject.

The string includes the object's indirect status, and if indirect, its ID and generation number.

### try_as

```cpp
T * datalogics_interface::PDFObject::try_as()
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `T *`

Attempt to downcast this object to a derived Cos type such as `PDFString`, `PDFDict`, `PDFArray`, `PDFStream`, `PDFName`, `PDFInteger`, `PDFReal`, or `PDFBoolean`. Returns nullptr if the object's actual type doesn't match `T`.

### try_as

```cpp
const T * datalogics_interface::PDFObject::try_as() const
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `const T *`

Const overload of try_as(). Returns a const pointer, or nullptr.
