# FormSource

With `FormSource` you can add content to a [Form](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/form) object and insert it in the PDF document. The following sections are covered:

* [Creating a FormSource](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/overview#creating-a-formsource)
* [FormSource Properties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/overview#properties)
* [Adding Content to a FormSource Object](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/overview#adding-content-to-a-formsource-object)
* [Inserting a FormSource into a Document](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/overview#inserting-a-formsource-into-a-document)

> note The `FormSource` content can also be an [SVG](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/svg) image or a [Barcode](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/barcode).

## Creating a FormSource

The `FormSource` class exposes a default constructor that you can use to create an empty instance.

**Example 1: Create FormSource**

```C#
FormSource formSource = new FormSource();
```

The snippet from **Example 1** creates an empty `FormSource` object. To fill this object with content, use [FixedContentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/fixedcontenteditor) as described later in this article.

The `FormSource` class exposes the following properties:

| Property  | Description                        |
| --------- | ---------------------------------- |
| `Size`    | Gets or sets the size of the form. |
| `Content` | Gets the contents of the form.     |

## Adding Content to a FormSource Object

The `FormSource` class inherits from the `IContentRootElement` interface. This inheritance allows you to use the [FixedContentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/fixedcontenteditor) class to fill the content of the form.

**Example 2** shows how to insert content into a `FormSource` object by using `FixedContentEditor`.

> There is no nesting limit for [Form XObjects](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/form), but PDF viewers may restrict depth to avoid memory or performance issues and improve responsiveness. This restriction can affect rendering depending on the viewer.

**Example 2: Add content to a FormSource**

```C#
FormSource simpleForm = new FormSource();
simpleForm.Size = new Size(310, 250);

FixedContentEditor formEditor = new FixedContentEditor(simpleForm);
formEditor.Position.Translate(50, 60);

using (formEditor.SaveProperties())
{
    formEditor.GraphicProperties.IsFilled = true;
    formEditor.GraphicProperties.IsStroked = true;
    formEditor.GraphicProperties.StrokeThickness = 2;
    formEditor.GraphicProperties.StrokeColor = new RgbColor(92, 229, 0);
    formEditor.GraphicProperties.FillColor = new RgbColor(213, 222, 226);
    formEditor.GraphicProperties.StrokeDashArray = new double[] { 17, 4 };
    formEditor.DrawRectangle(new Rect(0, 0, 250, 150));
}

formEditor.Position.Translate(100, 120);
formEditor.DrawText("Sample rectangle in a form");
```

## Inserting a FormSource into a Document

After you generate the `FormSource` object and fill it with content, insert it in the document. The API provides you with several approaches to insert the form in different scenarios.

> You can reuse a single `FormSource` object across the document by setting it to different [Form](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/form) instances.

* The `FixedContentEditor` allows you to add a form to a container.

  **Add a FormSource to a document using FixedContentEditor**

  ```C#
  FixedContentEditor documentPageEditor = new FixedContentEditor(document.Pages.AddPage());

  FormSource simpleForm = new FormSource();
  // Fill the FormSource instance with content (you can use the code from Example 2)

  documentPageEditor.DrawForm(simpleForm);
  ```

  There are several overloads of the `DrawForm()` method that let you specify the size of the form.

* You can insert a `FormSource` object by using the methods of `RadFixedDocumentEditor`. The `InsertFormInline()` method is described in the [RadFixedDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/radfixeddocumenteditor) article.

* When editing a `Block`, you can insert a `FormSource` object directly into it. For more information, see the [Block](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/block) article.

## See Also

* [SVG FormSource](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/svg)
* [Barcode FormSource](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/formsource/barcode)
