# Form Class

> Represents a PDF form XObject.

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

```cpp
class Form : Element
```

**Namespace:** `datalogics_interface`

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

## Description

Represents a PDF form XObject.

This is not to be confused with a PDF fillable form; a Form XObject is an object outside the page content stream.

A form XObject is a way to group a number of PDF objects together, into a single container. A Form XObject can hold both text and images, and can be defined once within a PDF file and then reused multiple times in the same PDF, and across multiple pages.

**Referenced by:** [`Annotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Annotation.md), [`CircleAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/CircleAnnotation.md), [`Form`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Form.md), [`FreeTextAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/FreeTextAnnotation.md), [`HighlightAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/HighlightAnnotation.md), [`InkAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/InkAnnotation.md), [`LineAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/LineAnnotation.md), [`LinkAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/LinkAnnotation.md), [`OCREngine`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OCREngine.md), [`PolyLineAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PolyLineAnnotation.md), [`PolygonAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PolygonAnnotation.md), [`Redaction`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Redaction.md), [`SquareAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/SquareAnnotation.md), [`TextMarkupAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextMarkupAnnotation.md), [`UnderlineAnnotation`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/UnderlineAnnotation.md)

**Uses types:** [`Clip`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md), [`Content`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Content.md), [`Element`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md), [`ElementCloneFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementCloneFlags.md), [`ElementType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementType.md), [`Form`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Form.md), [`GraphicState`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md), [`Matrix`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md), [`OptionalContentMembershipDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OptionalContentMembershipDict.md), [`PDFStream`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFStream.md), [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)

## Constructors

### Form

```cpp
datalogics_interface::Form::Form(Content &content, Document &document)
```

*constructor*

**Parameters**

- `content` ([`Content &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Content.md)): The content from which to create the form
- `document` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md)): the document in which the image is intended to be used.

Create a form with the given Content.

Specifying the document optimizes data usage for this image within that document.

### Form

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

*constructor*

**Parameters**

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

### ~Form

```cpp
datalogics_interface::Form::~Form() override
```

*destructor*

## Methods

### clear_content

```cpp
void datalogics_interface::Form::clear_content()
```

**Returns:** `void`

Removes the content from this form.

### clear_graphic_state

```cpp
void datalogics_interface::Form::clear_graphic_state()
```

**Returns:** `void`

Removes the graphic state from this form.

### clear_optional_content_membership_dict

```cpp
void datalogics_interface::Form::clear_optional_content_membership_dict()
```

**Returns:** `void`

Removes the optional content membership dictionary from this form.

### clone

```cpp
std::unique_ptr< Element > datalogics_interface::Element::clone(ElementCloneFlags flags) const
```

**Parameters**

- `flags` ([`ElementCloneFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementCloneFlags.md))

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

The copied element.

Makes a copy of the element.

Make a copy of an element to obtain a new element that has a distinct set of attributes.

Note: TextRun objects may not be cloned.

### clone

```cpp
std::unique_ptr< Form > datalogics_interface::Form::clone() const
```

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

The newly created form object.

Creates a new form from an existing form object. Creates a copy of the Form, including the underlying Content.

### get_bounding_box

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

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

The bounding box for this element. The coordinates of the bounding box are specified in user space coordinates, relative to the element's Content. Note that user space coordinates correspond to unrotated pages; any rotation specified in the page dictionary is not taken into account.

The bounding box for this element.

The bounding box is a rectangle that is guaranteed to encompass the element, but it is not guaranteed to be the smallest box that could contain the element. For example, if the element is a Path that contains an arc, the bounding box encompasses the bezier control points, and not just the curve itself.

### get_clip

```cpp
std::unique_ptr< Clip > datalogics_interface::Element::get_clip()
```

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

The current Clip for this Element, or NULL if no clip is set.

Gets the current Clip for an Element.

### get_content

```cpp
std::unique_ptr< Content > datalogics_interface::Form::get_content() const
```

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

The Content of the form.

The Content contained in the form.

Returns the content associated with this form XObject.

### get_element_type

```cpp
ElementType datalogics_interface::Element::get_element_type() const
```

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

Returns the runtime type of this element.

### get_graphic_state

```cpp
std::unique_ptr< GraphicState > datalogics_interface::Form::get_graphic_state()
```

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

The GraphicState of this Form, or null if none is set.

Get the graphic state of this Form.

May return null if this element does not have a GraphicState.

### get_matrix

```cpp
Matrix datalogics_interface::Element::get_matrix() const
```

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

The current transformation matrix applied to this element.

The transformation matrix for the element.

### get_optional_content_membership_dict

```cpp
std::unique_ptr< OptionalContentMembershipDict > datalogics_interface::Form::get_optional_content_membership_dict() const
```

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

the OptionalContentMembershipDict

The OptionalContentMembershipDict property for this Form.

Setting this property will attach the Form to an OptionalContentMembershipDict; it will then be associated with the OptionalContentGroups and be subject to the VisibilityPolicy and VisibilityExpression of that MembershipDict.

By setting this property to null, the Form is detached from any OptionalContentMembershipDict.

### get_stream

```cpp
std::unique_ptr< PDFStream > datalogics_interface::Form::get_stream()
```

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

The stream associated with the form.

Get the stream associated with the form.

Returns the underlying PDF stream (COS object) for this form XObject.

### operator=

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

**Parameters**

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

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

### rotate

```cpp
void datalogics_interface::Element::rotate(double theta)
```

**Parameters**

- `theta` (`double`): The rotation angle in degrees.

**Returns:** `void`

Rotate an element by theta degrees counterclockwise using the matrix [ cos T sin T -sin T cos T 0 0 ].

### scale

```cpp
void datalogics_interface::Element::scale(double sx, double sy)
```

**Parameters**

- `sx` (`double`): The horizontal scale factor.
- `sy` (`double`): The vertical scale factor.

**Returns:** `void`

Scale an element by (sx,sy) units using the matrix [ sx 0 0 sy 0 0 ].

### set_clip

```cpp
void datalogics_interface::Element::set_clip(Clip &clip)
```

**Parameters**

- `clip` ([`Clip &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md)): The clip to set as the current clip for this element, or NULL to remove clipping.

**Returns:** `void`

Sets the current Clip for an Element.

### set_content

```cpp
void datalogics_interface::Form::set_content(const Content &content)
```

**Parameters**

- `content` ([`const Content &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Content.md)): The new content for the form.

**Returns:** `void`

Set the Content of the form.

Setting new content also dynamically recalculates the form's bounding box.

### set_graphic_state

```cpp
void datalogics_interface::Form::set_graphic_state(const GraphicState &gstate)
```

**Parameters**

- `gstate` ([`const GraphicState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)): The new/updated Graphic State for the Form.

**Returns:** `void`

Set the Graphic State of this Form.

### set_matrix

```cpp
void datalogics_interface::Element::set_matrix(const Matrix &matrix)
```

**Parameters**

- `matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): The transformation matrix for the element.

**Returns:** `void`

Set the transformation matrix for the element.

### set_optional_content_membership_dict

```cpp
void datalogics_interface::Form::set_optional_content_membership_dict(const OptionalContentMembershipDict &ocmd)
```

**Parameters**

- `ocmd` ([`const OptionalContentMembershipDict &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/OptionalContentMembershipDict.md)): the OptionalContentMembershipDict

**Returns:** `void`

The OptionalContentMembershipDict property for this Form.

Setting this property will attach the Form to an OptionalContentMembershipDict; it will then be associated with the OptionalContentGroups and be subject to the VisibilityPolicy and VisibilityExpression of that MembershipDict.

By setting this property to null, the Form is detached from any OptionalContentMembershipDict.

### translate

```cpp
void datalogics_interface::Element::translate(double tx, double ty)
```

**Parameters**

- `tx` (`double`): The horizontal translation distance in user space units.
- `ty` (`double`): The vertical translation distance in user space units.

**Returns:** `void`

Translate an element by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ].

### try_as

```cpp
T * datalogics_interface::Element::try_as()
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `T *`

Attempt to downcast this element to a derived type. Returns a pointer to the derived type, or nullptr if the type doesn't match.

### try_as

```cpp
const T * datalogics_interface::Element::try_as() const
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `const T *`

Const overload of try_as(). Returns a const pointer, or nullptr.
