Form
Form is a content element that contains a form source and represents a Form XObject. Form XObjects allow you to describe objects (text, images, vector elements, and so on) within a PDF file and reuse this content throughout the document.
Public API
| Property | Description |
|---|---|
FormSource | Specifies the content that the Form object visualizes. It is of type FormSource. |
Clipping | Gets or sets the clipping of the form object. |
Width | The width of the form. |
Height | The height of the form. |
AlphaConstant | Specifies the constant shape or constant opacity value for nonstroking operations. |
StrokeAlphaConstant | Specifies the constant shape or constant opacity value for stroking operations. |
Position | The Position of the form inside the IContainerElement. |
Parent | Gets the parent page of the form. |
| Method | Description |
|---|---|
Clone (starting with Q2 2025) | Creates a deep copy of this document element. |
Creating and Inserting a Form
The Form class exposes a default public constructor that allows you to create instances of it. Form is a content element and you can add such an object to the Content collection of an IContainerElement such as RadFixedPage.
Example 1 shows how to initialize a Form object and add it to a previously defined container.
Example 1: Create a form and add it to an IContainerElement
Form emptyForm = new Form();
container.Content.Add(emptyForm);
Example 2 demonstrates how to use one of the factory methods of the ContentElementCollection to create a new form and insert it into the respective container.
Example 2: Add a form to a container
Form form = container.Content.AddForm();
Form formWithSource = container.Content.AddForm(sampleFormSource);
There are other methods that allow adding a form to a document by passing its size and source. You can use them through the FixedContentEditor class.
You can add content to the form by setting its
FormSourceproperty. The API also allows you to directly pass theFormSourceto a method that automatically generates a form in the document content. For more information, see the FormSource article.
There is no nesting limit for Form XObjects, but PDF viewers may restrict depth to avoid memory or performance issues and improve responsiveness. This can affect rendering depending on the viewer.
Modifying Form Properties
You can modify a Form element using the properties the class exposes. The properties are listed in the Public API section.
Example 3: Modify Form properties
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();
FormSource formSource = new FormSource();
formSource.Size = new Size(200, 200);
Form newForm = page.Content.AddForm(formSource);
SimplePosition simplePosition = new SimplePosition();
simplePosition.Translate(20, 20);
newForm.Width = 200;
newForm.Height = 300;
newForm.Position = simplePosition;
newForm.AlphaConstant = 0.5;
newForm.StrokeAlphaConstant = 0.1;
PathGeometry pathGeometry = new PathGeometry();
PathFigure pathFigure = pathGeometry.Figures.AddPathFigure();
pathFigure.StartPoint = new Point(5, 5);
LineSegment lineSegment = pathFigure.Segments.AddLineSegment();
lineSegment.Point = new Point(205, 5);
BezierSegment bezierSegment = pathFigure.Segments.AddBezierSegment();
bezierSegment.Point1 = new Point(105, 50);
bezierSegment.Point2 = new Point(130, 105);
bezierSegment.Point3 = new Point(100, 200);
pathFigure.IsClosed = true;
FixedContentEditor editor = new FixedContentEditor(formSource);
editor.DrawPath(pathGeometry);
