Get Started
Usage API
More information

Structure of a form

A form document has exactly the same structure as a text document. The only difference is a new forms entity placed with other paragraph elements – text runs, inline text content controls and hyperlinks. There are four form types: text field, combo box, checkbox and picture form.

Thus any form document structure with ONLYOFFICE Document Builder API used to create it can be outlined like this:

ONLYOFFICE Document Builder API

Document and document elements creation:
Api

Document

The main document properties, global color and fill/stroke settings, styles used throughout the document:
ApiDocumentContent, ApiDocument, ApiStyle, ApiFill, ApiStroke, ApiGradientStop, ApiUniColor, ApiPresetColor, ApiRGBColor, ApiSchemeColor

Section

Document section properties:
ApiSection

Paragraph

Common paragraph properties, common text properties, current paragraph properties, paragraph numbering:
ApiParaPr, ApiTextPr, ApiParagraph, ApiNumbering, ApiNumberingLevel

Text run

Common text properties, current text run properties:
ApiTextPr, ApiRun

Image

Common object properties, current image properties:
ApiDrawing, ApiImage

Chart

Common object properties, current chart properties:
ApiDrawing, ApiChart

Shape

Common object properties, current shape properties:
ApiDrawing, ApiShape.

If a place for text is provided inside the shape, the whole paragraph structure can be inserted into it.

Inline text content control

Common text properties, current inline text content control properties:
ApiTextPr, ApiInlineLvlSdt

Text run

Inline text content control

Text form

Common object properties, common text properties, current text form properties:
ApiFormBase, ApiTextPr, ApiTextForm

Combo box form

Common object properties, common text properties, current combo box form properties:
ApiFormBase, ApiTextPr, ApiComboBoxForm

Checkbox form

Common object properties, common text properties, current checkbox form properties:
ApiFormBase, ApiTextPr, ApiCheckBoxForm

Picture form

Common object properties, common text properties, current picture form properties:
ApiFormBase, ApiTextPr, ApiPictureForm

Table

Common table styles, common table properties, current table properties:
ApiTableStylePr, ApiTablePr, ApiTable

Table row

Common table row properties, current table row properties:
ApiTableRowPr, ApiTableRow

Table cell

Common table cell properties, current table row properties:
ApiTableCellPr, ApiTableCell

Paragraph

Table

Block content control

Table cell

Common table cell properties, current table row properties:
ApiTableCellPr, ApiTableCell

Paragraph

Table

Block content control

Block content control

Common text properties, current block content control properties:
ApiTextPr, ApiBlockLvlSdt

Paragraph

Table

Block content control

Range

Common text properties, current range properties:
ApiTextPr, ApiRange

Paragraph

Table

Block content control

 

Creating a new form document

The simplest example form document with a single text form containing the "John Smith" text can be built with the help of ONLYOFFICE Document Builder using the following code:

builder.CreateFile("docxf");                      // create a form document file in the .docxf format with ONLYOFFICE Document Builder
var oDocument = Api.GetDocument();                // create a new 'oDocument' variable and get the created text document contents
var oTextForm = Api.CreateTextForm();             // create an empty text form
var oParagraph = oDocument.GetElement(0);         // get the first empty paragraph from the created document
oParagraph.AddElement(oTextForm);                 // add the created text form to the first paragraph
oTextForm.SetText("John Smith");                  // add the "John Smith" text to the text form
builder.SaveFile("docxf", "example.docxf");       // save the resulting form document as a file in the .docxf format with the 'example.docxf' name
builder.CloseFile();                              // close the form document file and finish work with ONLYOFFICE Document Builder

Opening an existing form document

If you want to edit an already existing form document, you can open it using ONLYOFFICE Document Builder, get its elements and change them however you need. The only difference from a document editor in this case will be that you will not need this document editor. The document is opened the following way:

builder.OpenFile("https://example.com/myformdocument.docxf");        // use a path to an existing 'myformdocument.docxf' form document file to open it with ONLYOFFICE Document Builder
var oDocument = Api.GetDocument();                // create a new 'oDocument' variable and get the created text document contents
var oTextForm = Api.CreateTextForm();             // create an empty text form
var oParagraph = oDocument.GetElement(0);         // get the first empty paragraph from the created document
oParagraph.AddElement(oTextForm);                 // add the created text form to the first paragraph
oTextForm.SetText("John Smith");                  // add the "John Smith" text to the text form
builder.SaveFile("docxf", "example.docxf");       // save the resulting form document as a file in the .docxf format with the 'example.docxf' name
builder.CloseFile();                              // close the form document file and finish work with ONLYOFFICE Document Builder

As you can see you just need to use the builder.OpenFile(); method of the CDocBuilder class with the path to the necessary form document as an argument to open it. In the above example we open myformdocument.docxf document, get its first paragraph and add the text form with the "John Smith" text to it. The same way any other form document element can be changed.

Use the appropriate API documentation sections to find out which methods allow you to change certain document and spreadsheet element formatting properties.