Get Started
Usage API
More information

ApiFormBase

new ApiFormBase()

Class representing a document form base.

Properties

Name Type Description
key string

Form key.

tip string

Form tip text.

required boolean

Specifies if the form is required or not.

placeholder string

Form placeholder text.

Methods

Name Description
Clear

Clears the current form.

Copy

Copies the current form (copies with the shape if it exists).

GetClassType

Returns a type of the ApiFormBase class.

GetFormKey

Returns the current form key.

GetFormType

Returns a type of the current form.

GetText

Returns the text from the current form. This method is used only for text and combo box forms.

GetTextPr

Returns the text properties from the current form. *This method is used only for text and combo box forms.

GetTipText

Returns the tip text of the current form.

GetWrapperShape

Returns a shape in which the form is placed to control the position and size of the fixed size form frame. The null value will be returned for the inline forms.

IsFixed

Checks if the current form is fixed size.

IsRequired

Checks if the current form is required.

SetBackgroundColor

Sets the background color to the current form.

SetBorderColor

Sets the border color to the current form.

SetFormKey

Sets a key to the current form.

SetPlaceholderText

Sets the placeholder text to the current form. Can't be set to checkbox or radio button.

SetRequired

Specifies if the current form should be required.

SetTextPr

Sets the text properties to the current form. *This method is used only for text and combo box forms.

SetTipText

Sets the tip text to the current form.

ToFixed

Converts the current form to a fixed size form.

ToInline

Converts the current form to an inline form. Picture form can't be converted to an inline form, it's always a fixed size object.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oTextForm = Api.CreateTextForm({"key": "Personal information", "tip": "Enter your first name", "required": true, "placeholder": "First name", "comb": true, "maxCharacters": 10, "cellWidth": 3, "multiLine": false, "autoFit": false});
var oParagraph = oDocument.GetElement(0);
oParagraph.AddElement(oTextForm);
oTextForm.SetBorderColor(255, 0, 0);
oTextForm.ToFixed(10 * 240, 2 * 240);
oTextForm.SetText("John Smith");
var oTextPr = oDocument.GetDefaultTextPr();
oTextPr.SetFontSize(30);
oTextPr.SetBold(true);
oTextForm.SetTextPr(oTextPr);
var oFormTextPr = oTextForm.GetTextPr();
oFormTextPr.SetItalic(true);
var oShape = oTextForm.GetWrapperShape();
var oStroke = Api.CreateStroke(36000, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 0)));
oShape.SetOutLine(oStroke);
var oCopyForm = oTextForm.Copy();
oParagraph = Api.CreateParagraph();
oParagraph.AddElement(oCopyForm);
oDocument.Push(oParagraph);
oCopyForm.ToInline();
var sText = oTextForm.GetText();
var sClassType = oTextForm.GetClassType();
var sFormType = oTextForm.GetFormType();
var bFixed = oTextForm.IsFixed();
var bFixedCopy = oCopyForm.IsFixed();
var bRequired = oTextForm.IsRequired();
var sKey = oTextForm.GetFormKey();
var sTipText = oTextForm.GetTipText();
oCopyForm.SetText("John Smith");
oCopyForm.Clear();
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Class type: " + sClassType);
oParagraph.AddLineBreak();
oParagraph.AddText("Form type: " + sFormType);
oParagraph.AddLineBreak();
oParagraph.AddText("Form text: " + sText);
oParagraph.AddLineBreak();
oParagraph.AddText("The first form from this document has a fixed size: " + bFixed);
oParagraph.AddLineBreak();
oParagraph.AddText("The second form from this document has a fixed size: " + bFixedCopy);
oParagraph.AddLineBreak();
oParagraph.AddText("The first form from this document is required: " + bRequired);
oParagraph.AddLineBreak();
oParagraph.AddText("Form key: " + sKey);
oParagraph.AddLineBreak();
oParagraph.AddText("Form tip text: " + sTipText);
oParagraph.AddLineBreak();
oParagraph.AddText("The second form from this document was cleared.");
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ApiFormBase.docx");
builder.CloseFile();

Resulting document