# Content Class

> Class that represents the collection of elements on a PDF page.

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

```cpp
class Content
```

**Namespace:** `datalogics_interface`

## Description

Class that represents the collection of elements on a PDF page.

A content object represents a collection of elements that make up a page in a PDF file. A content object is more convenient to use than directly parsing or working with a page content stream. This is because a page can include a large collection of individual stream objects. Working with a content object, you can avoid focusing on this level of detail. The content converts individual stream items to a structured form, making it unnecessary to parse the individual syntax for each one. A content object can be associated with a large amount of unmanaged memory in APDFL and should be deleted when the object is no longer in use.

The index associated with Content is 0-based, so 0 is the first element.

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

**Uses types:** [`AddPageFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/AddPageFlags.md), [`ColorSpace`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ColorSpace.md), [`Element`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md), [`Matrix`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md), [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)

## Constructors

### Content

```cpp
datalogics_interface::Content::Content()
```

*constructor*

Create content.

### Content

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

*constructor*

**Parameters**

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

### Content

```cpp
datalogics_interface::Content::Content(Element &first_elem)
```

*constructor*

**Parameters**

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

Create content.

### ~Content

```cpp
datalogics_interface::Content::~Content()
```

*destructor*

## Fields

### before_first

```cpp
static int datalogics_interface::Content::before_first
```

*static*

## Methods

### add_element

```cpp
void datalogics_interface::Content::add_element(const Element &elem)
```

**Parameters**

- `elem` ([`const Element &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md)): - The Element which is to be added to the end of the existing Content object.

**Returns:** `void`

Adds an existing Element at the end of the content object.

### add_element

```cpp
void datalogics_interface::Content::add_element(const Element &elem, int add_after_index)
```

**Parameters**

- `elem` ([`const Element &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md)): - The Element which is to be added to the end of the existing Content object.
- `add_after_index` (`int`)

**Returns:** `void`

Adds an existing Element at the end of the content object.

### add_page

```cpp
void datalogics_interface::Content::add_page(int insert_after_index, Document &container_doc, Page &src_page, std::optional< Matrix > dst_matrix, std::optional< std::vector< std::string > > annot_types, AddPageFlags flags, std::optional< Rect > bbox)
```

**Parameters**

- `insert_after_index` (`int`): The index indicates the location after which the specified element is to be added. The index should be BeforeFirst to add to the beginning of the display list.
- `container_doc` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md)): The Document in which the page is contained.
- `src_page` ([`Page &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Page.md)): The page that will be inserted at insertAfterIndex in theContent.
- `dst_matrix` ([`std::optional< Matrix >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): (May be NULL) The matrix applied to the default matrix of the Page that is inserted into the Document.
- `annot_types` (`std::optional< std::vector< std::string > >`): If the page contains annotations, the annotTypes list is used to determine which annotation types are pumped into the page contents of the CosDoc.
- `flags` ([`AddPageFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/AddPageFlags.md)): (May be 0) AllAnnotations specifies all annotation types. If this is not set, then the annotTypes list will be consulted.
- `bbox` ([`std::optional< Rect >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)): (May be NULL) specifies the destination BBox for the page being inserted. If it is NULL, the new page's media box is used.

**Returns:** `void`

Adds the specfied Page to the Content as a Form. It adds a reference to the Xobject form at the indicated index in the Content; the index may be less than 0, which indicates the object is to be appended to the content.

### flatten_optional_content

```cpp
bool datalogics_interface::Content::flatten_optional_content(OptionalContentContext &occ)
```

**Parameters**

- `occ` ([`OptionalContentContext &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OptionalContentContext.md)): The optional content context in which content is checked for visibility.

**Returns:** `bool`

true if the content was successfully flattened, false otherwise.

Flattens optional content within this Content object.

Removes elements that are not visible in the given optional content context and removes optional content information from any visible elements.

The optional content information formerly associated with this Content object will NOT be deleted from the document, as it is possible that content elsewhere in the document may be using the information.

### get_bounding_box

```cpp
Rect datalogics_interface::Content::get_bounding_box() const
```

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

A Rect representing the bounding box of all elements in this Content.

The bounding box for this content.

The bounding box is a rectangle that is at least large enough to contain the bounding boxes for all the elements in the Content.

### get_default_color_space

```cpp
std::unique_ptr< ColorSpace > datalogics_interface::Content::get_default_color_space(const std::string &name) const
```

**Parameters**

- `name` (`const std::string &`): The name of the color space to get. It must be one of DefaultRGB, DefaultCMYK, or DefaultGray.

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

The color space used as the default. May return null if no default is set.

Get a default color space from a Content object.

See Section 4.5.4 in the PDF Reference for more information about default color spaces.

### get_element

```cpp
std::unique_ptr< Element > datalogics_interface::Content::get_element(int index) const
```

**Parameters**

- `index` (`int`): The zero-based index of the element to retrieve.

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

The Element at the specified index.

Get the element specified by index.

### get_num_elements

```cpp
int datalogics_interface::Content::get_num_elements() const
```

**Returns:** `int`

The number of elements contained in this Content.

The number of elements in the Content object.

### operator=

```cpp
Content & datalogics_interface::Content::operator=(Content &&) noexcept
```

**Parameters**

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

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

### remove_element

```cpp
void datalogics_interface::Content::remove_element(int index)
```

**Parameters**

- `index` (`int`): - The position at which to remove the Element

**Returns:** `void`

Removes the Element at the specified index.

### set_default_color_space

```cpp
void datalogics_interface::Content::set_default_color_space(const std::string &name, const ColorSpace &color_space)
```

**Parameters**

- `name` (`const std::string &`): The name of the color space to set. It must be one of DefaultRGB, DefaultCMYK, or DefaultGray.
- `color_space` ([`const ColorSpace &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/ColorSpace.md)): The color space to set. It may not be a Lab, Indexed or Pattern color space.

**Returns:** `void`

Set a default color space from a Content object.

See Section 4.5.4 in the PDF Reference for more information about default color spaces.

### to_string

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

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

A string describing this Content object.

Returns a string representation of this Content object.

The string includes the number of elements in the Content.
