# Content Class

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

- Product: Adobe PDF Library 21
- Language: .NET Framework
- Version: APDFL21.0.0PlusP1e
- HTML page: https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Content
- Version index: https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/llms.txt

```csharp
class Content : SystemIDisposable
```

**Namespace:** `Datalogics::PDFL`

**Inherits from:** `SystemIDisposable`

## 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/DotNetFramework/APDFL21.0.0PlusP1e/class/Container.md), [`Form`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Form.md), [`Group`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Group.md), [`Page`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Page.md)

**Uses types:** [`AddPageFlags`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/AddPageFlags.md), [`ColorSpace`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/ColorSpace.md), [`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md), [`Element`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Element.md), [`Matrix`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Matrix.md), [`OptionalContentContext`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentContext.md), [`Page`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Page.md), [`Rect`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Rect.md)

## Constructors

### Content

```csharp
Datalogics.PDFL.Content.Content()
```

*constructor*

Create content

### Content

```csharp
Datalogics.PDFL.Content.Content(Element firstElem)
```

*constructor*

**Parameters**

- `firstElem` ([`Element`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Element.md)): The Element which is to be added to the beginning of the new Content object.

Create content with a first Element.

## Properties

### BoundingBox

```csharp
Rect Datalogics.PDFL.Content.BoundingBox { get; }
```

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.

### NumElements

```csharp
int Datalogics.PDFL.Content.NumElements { get; }
```

The number of elements in the Content object.

## Fields

### BeforeFirst

```csharp
static const int Datalogics.PDFL.Content.BeforeFirst
```

*static*

Position for inserting an element before the first element.

## Methods

### AddElement

```csharp
void Datalogics.PDFL.Content.AddElement(Element NewElem)
```

**Parameters**

- `NewElem` ([`Element`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/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.

### AddElement

```csharp
void Datalogics.PDFL.Content.AddElement(Element NewElem, int addAfterIndex)
```

**Parameters**

- `NewElem` ([`Element`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Element.md)): The Element which is to be added to the end of the existing Content object.
- `addAfterIndex` (`int`): The position after which to insert the new Element, the index is 0-based so 0 is the first element. To insert a new element as the first element use the Content.BeforeFirst constant.

**Returns:** `void`

Adds an existing Element at the given index of the content object.

### AddPage

```csharp
void Datalogics.PDFL.Content.AddPage(int insertAfterIndex, Document containerDoc, Page srcPage, Matrix dstMatrix, System.Collections.Generic.IList< System.String > annotTypes, AddPageFlags flags, Rect bbox)
```

**Parameters**

- `insertAfterIndex` (`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.
- `containerDoc` ([`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md)): The Document in which the page is contained.
- `srcPage` ([`Page`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Page.md)): The page that will be inserted at insertAfterIndex in theContent.
- `dstMatrix` ([`Matrix`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Matrix.md)): (May be NULL) The matrix applied to the default matrix of the Page that is inserted into the Document.
- `annotTypes` (`System.Collections.Generic.IList< System.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/DotNetFramework/APDFL21.0.0PlusP1e/enum/AddPageFlags.md)): (May be 0) AllAnnotations specifies all annotation types. If this is not set, then the annotTypes list will be consulted.
- `bbox` ([`Rect`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/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.

### Dispose

```csharp
void Datalogics.PDFL.Content.Dispose()
```

**Returns:** `void`

### FlattenOptionalContent

```csharp
bool Datalogics.PDFL.Content.FlattenOptionalContent(OptionalContentContext occ)
```

**Parameters**

- `occ` ([`OptionalContentContext`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/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.

### GetDefaultColorSpace

```csharp
ColorSpace Datalogics.PDFL.Content.GetDefaultColorSpace(string name)
```

**Parameters**

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

**Returns:** [`ColorSpace`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/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.

### GetElement

```csharp
Element Datalogics.PDFL.Content.GetElement(int index)
```

**Parameters**

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

**Returns:** [`Element`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Element.md)

The Element at the specified index.

Get the element specified by index.

### RemoveElement

```csharp
void Datalogics.PDFL.Content.RemoveElement(int index)
```

**Parameters**

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

**Returns:** `void`

Removes the Element at the specified index.

### SetDefaultColorSpace

```csharp
void Datalogics.PDFL.Content.SetDefaultColorSpace(string name, ColorSpace colorSpace)
```

**Parameters**

- `name` (`string`): The name of the color space to set. It must be one of DefaultRGB, DefaultCMYK, or DefaultGray.
- `colorSpace` ([`ColorSpace`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/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.

### ToString

```csharp
override string Datalogics.PDFL.Content.ToString()
```

**Returns:** `override 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.
