# PDFObject Class

> Represents the underlying simple data element of an object in 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/PDFObject
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class PDFObject
```

**Namespace:** `datalogics_interface`

**Derived classes:** [`PDFArray`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFArray.md), [`PDFBoolean`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFBoolean.md), [`PDFDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md), [`PDFInteger`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFInteger.md), [`PDFName`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFName.md), [`PDFReal`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFReal.md), [`PDFStream`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFStream.md), [`PDFString`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFString.md)

## Description

Represents the underlying simple data element of an object in 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. For example, PDFInteger represents a single integer value. Others represent a collection of PDFObjects, such as PDFArray, an indexed array of data elements.

PDFObject is the superclass of these simple objects. A PDFObject cannot be directly instantiated, but any of its subclasses may.

Any PDFObject may be either direct or indirect. A direct object exists within its collection object (such as a PDFArray) and can be referenced only within that collection object. An indirect object exists outside of any collection object and can be referenced by many collection objects.

Threading: single-thread use. A `PDFObject` (and every subclass: `PDFDict`, `PDFArray`, `PDFStream`, `PDFString`, `PDFName`, `PDFInteger`, `PDFReal`, `PDFBoolean`) is bound to its owning `Document`'s thread. Do not share instances across threads. See `datalogics_interface.hpp` for the full threading model.

**Referenced by:** [`AxialShadingPattern`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/AxialShadingPattern.md), [`CalGrayColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/CalGrayColorSpace.md), [`CalRGBColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/CalRGBColorSpace.md), [`ColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ColorSpace.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), [`FileSpecification`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/FileSpecification.md), [`ICCBasedColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ICCBasedColorSpace.md), [`IndexedColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/IndexedColorSpace.md), [`LabColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/LabColorSpace.md), [`NameTree`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/NameTree.md), [`NamedColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/NamedColorSpace.md), [`NumberTree`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/NumberTree.md), [`PDFArray`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFArray.md), [`PDFDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md), [`Page`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Page.md), [`Pattern`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Pattern.md), [`RemoteDestination`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/RemoteDestination.md), [`SeparationColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/SeparationColorSpace.md), [`ShadingPattern`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ShadingPattern.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)

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

## Constructors

### PDFObject

```cpp
datalogics_interface::PDFObject::PDFObject(PDFObject &&) noexcept
```

*constructor*

**Parameters**

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

### ~PDFObject

```cpp
virtual datalogics_interface::PDFObject::~PDFObject()
```

*destructor*

## Methods

### 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_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
PDFObject & datalogics_interface::PDFObject::operator=(PDFObject &&) noexcept
```

**Parameters**

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

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

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