# PDFArray Class

> Represents an array 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/PDFArray
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class PDFArray : PDFObject
```

**Namespace:** `datalogics_interface`

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

## Description

Represents an array 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. For example, PDFInteger represents a single integer value. Others represent a collection of PDFObjects, like PDFArray, an indexed array of data elements.

A PDFArray is a heterogenous collection object that gathers other PDFObjects (including other PDFArrays) into an indexed list.

**Referenced by:** [`OptionalContentMembershipDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OptionalContentMembershipDict.md), [`ViewDestination`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ViewDestination.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

### PDFArray

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

*constructor*

**Parameters**

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

General constructor

## Methods

### add

```cpp
void datalogics_interface::PDFArray::add(PDFObject &value)
```

**Parameters**

- `value` ([`PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)): the object to append.

**Returns:** `void`

Adds an object to the end of the array

### get

```cpp
std::unique_ptr< PDFObject > datalogics_interface::PDFArray::get(int index)
```

**Parameters**

- `index` (`int`): the position of the object to retrieve.

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

Returns the object at the given index.

### 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
int datalogics_interface::PDFArray::get_length() const
```

**Returns:** `int`

The number of elements in this array.

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

### insert

```cpp
void datalogics_interface::PDFArray::insert(int index, PDFObject &value)
```

**Parameters**

- `index` (`int`): the position at which to insert.
- `value` ([`PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)): the object to insert.

**Returns:** `void`

Inserts an object at the given index, displacing existing objects. All objects following this will have their index increased by one.

### 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::PDFArray::put(int index, PDFObject &value)
```

**Parameters**

- `index` (`int`): the position at which to place the object.
- `value` ([`PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)): the object to place at the given index.

**Returns:** `void`

Puts an object at the given index, replacing the existing item. The index can be greater than the current length of the array; the array will be extended and the empty slots filled with null objects.

### remove_at

```cpp
void datalogics_interface::PDFArray::remove_at(int index)
```

**Parameters**

- `index` (`int`): the position of the object to remove.

**Returns:** `void`

Removes the object at the given index. The length of the array is reduced by 1.

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