# PDFDict Class

> Represents an associative collection of data elements 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/PDFDict
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class PDFDict : PDFObject
```

**Namespace:** `datalogics_interface`

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

## Description

Represents an associative collection of data elements 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, such as PDFInteger, which represents a single integer value. Other subclasses represent a collection of PDFObjects, like PDFArray, an indexed array of data elements.

A PDFDict is a heterogenous collection object that maps other PDFObjects (including other PDFDicts) to PDFName objects.

**Referenced by:** [`Action`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Action.md), [`Bookmark`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Bookmark.md), [`Container`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Container.md), [`DeviceNColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/DeviceNColorSpace.md), [`Document`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md), [`Font`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md), [`GoToAction`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GoToAction.md), [`LaunchAction`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/LaunchAction.md), [`NameTree`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/NameTree.md), [`NumberTree`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/NumberTree.md), [`OptionalContentConfig`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OptionalContentConfig.md), [`OptionalContentGroup`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OptionalContentGroup.md), [`PDFStream`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFStream.md), [`Page`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Page.md), [`RemoteGoToAction`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/RemoteGoToAction.md), [`StructElement`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/StructElement.md), [`StructTreeRoot`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/StructTreeRoot.md), [`URIAction`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/URIAction.md)

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

## Constructors

### PDFDict

```cpp
datalogics_interface::PDFDict::PDFDict(Document &doc, bool indirect)
```

*constructor*

**Parameters**

- `doc` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md)): Document object containing this PDFDict
- `indirect` (`bool`): flag marking this as an indirect PDFObject

General constructor

## Methods

### contains

```cpp
bool datalogics_interface::PDFDict::contains(const std::string &key)
```

**Parameters**

- `key` (`const std::string &`): A PDFName for the key

**Returns:** `bool`

true if the given key exists

Tests whether the given key exists in the dictionary

### get

```cpp
std::unique_ptr< PDFObject > datalogics_interface::PDFDict::get(const std::string &key)
```

**Parameters**

- `key` (`const std::string &`): A PDFName for the key

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

A PDFObject matching the key

Returns the object matching the given key.

### 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_keys

```cpp
std::vector< std::string > datalogics_interface::PDFDict::get_keys() const
```

**Returns:** `std::vector< std::string >`

a list of all the keys

Enumerate all keys in this dictionary. Order is undefined; successive calls on the same dictionary are not guaranteed to return keys in the same order. Get a list of all keys in the dictionary

### 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.

### put

```cpp
void datalogics_interface::PDFDict::put(const std::string &key, PDFObject &value)
```

**Parameters**

- `key` (`const std::string &`): A PDFName for the key
- `value` ([`PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)): A PDFObject to add to the dictionary

**Returns:** `void`

Puts an object with the matching key into the dictionary, adding the entry if the key is not already present.

### remove

```cpp
void datalogics_interface::PDFDict::remove(const std::string &key)
```

**Parameters**

- `key` (`const std::string &`): A PDFName for the key

**Returns:** `void`

Removes a key/object pair from the dictionary.

### 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.
