Table of Contents

Class PdfTextBoxField

Namespace
Syncfusion.Pdf.Interactive
Assembly
Syncfusion.Pdf.Portable.dll

Represents text box field in the PDF form.

public class PdfTextBoxField : PdfAppearanceField, INotifyPropertyChanged
Inheritance
PdfTextBoxField
Implements
Inherited Members

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");  
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")   
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)

Remarks

This PdfTextBoxField class is used to create the text box field in PDF forms. Please refer the UG docuemntation link for more details.

Constructors

PdfTextBoxField(PdfPageBase, string)

Initializes a new instance of the PdfTextBoxField class with the provided page and name.

public PdfTextBoxField(PdfPageBase page, string name)

Parameters

page PdfPageBase

Page which the field to be placed on.

name string

The name of the text box field.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");  
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")   
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
See Also

Properties

AutoResizeText

Gets or sets a value indicating whether this is AutoResizeText.

public bool AutoResizeText { get; set; }

Property Value

bool

true if AutoResizeText field; otherwise, false.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();      
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
//Create a text box
PdfTextBoxField textBoxField = new PdfTextBoxField(page, "firstNameTextBox");
textBoxField.AutoResizeText = true;
textBoxField.Flatten = false;
//Set text.
textBoxField.Text = "Syncfusion provides the best third-party UI components for WinForms, WPF, ASP.NET Web Forms, MVC, Core, UWP, WinUI (Preview), Xamarin, JavaScript";
textBoxField.Bounds = new RectangleF(0, 0, 300, 20);
textBoxField.ToolTip = "Company Products";
//Add the textbox in document
document.Form.Fields.Add(textBoxField);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
'Create a text box
Dim firstNameTextBox As textBoxField = New PdfTextBoxField(page, "firstNameTextBox")
textBoxField.AutoResizeText = true
textBoxField.Flatten = false
//Set text.
textBoxField.Text = "Syncfusion provides the best third-party UI components for WinForms, WPF, ASP.NET Web Forms, MVC, Core, UWP, WinUI (Preview), Xamarin, JavaScript"
textBoxField.Bounds = New RectangleF(100, 20, 200, 20)
textBoxField.ToolTip = "Company Products"
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

ComplexScript

Gets or sets the complex script language support.

public bool ComplexScript { get; set; }

Property Value

bool

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a new PDF page.
PdfPage page = document.Pages.Add();
//Create font.
Font font = new Font("Tahoma", 10f);
//Create a new PDF font instance.
PdfFont pdfFont = new PdfTrueTypeFont(font, FontStyle.Regular, 10f, true, true);
//Create a new text box field.
PdfTextBoxField textBox = new PdfTextBoxField(page, "textBox");
//Set bounds
textBox.Bounds = new RectangleF(0, 0, 300, 20);
//Set font.
textBox.Font = pdfFont;
//Set text.
textBox.Text = "สวัสดีชาวโลก";
//Enable complex script.
textBox.ComplexScript = true;
//Add field to form.
document.Form.Fields.Add(textBox);
document.Form.SetDefaultAppearance(false)
//Save the document.
document.Save("output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a new PDF page.
Dim page As PdfPage = document.Pages.Add()
'Create font.
Dim font As New Font("Tahoma", 10F)
'Create a new PDF font instance.
Dim pdfFont As PdfFont = New PdfTrueTypeFont(font, FontStyle.Regular, 10F, True, True)
'Create a new text box field.
Dim textBox As New PdfTextBoxField(page, "textBox")
'Set bounds
textBox.Bounds = New RectangleF(0, 0, 300, 20)
'Set font.
textBox.Font = pdfFont
'Set text.
textBox.Text = "สวัสดีชาวโลก"
'Enable complex script.
textBox.ComplexScript = True
'Add field to form.
document.Form.Fields.Add(textBox)
document.Form.SetDefaultAppearance(False)
'Save the document.
document.Save("output.pdf")
'Close the document.
document.Close(True)
See Also

DefaultValue

Gets or sets the default value.

public string DefaultValue { get; set; }

Property Value

string

The default value of the text box field.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.DefaultValue = "Cris";
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.DefaultValue = "Cris"
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

InsertSpaces

Meaningful only if the MaxLength property is set and the Multiline, Password properties are false. If set, the field is automatically divided into as many equally spaced positions, or combs, as the value of MaxLength, and the text is laid out into those combs.

public bool InsertSpaces { get; set; }

Property Value

bool

true if need to insert spaces; otherwise, false.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.InsertSpaces = true;
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.InsertSpaces = True
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

MaxLength

Gets or sets the maximum number of characters that can be entered in the text box.

public int MaxLength { get; set; }

Property Value

int

An integer value specifying the maximum number of characters that can be entered in the text box.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.MaxLength = 8;
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.MaxLength = 8
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

Multiline

Gets or sets a value indicating whether this PdfTextBoxField is multiline.

public bool Multiline { get; set; }

Property Value

bool

true if multiline; otherwise, false.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.Multiline = true;
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.Multiline = True
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

Password

Gets or sets a value indicating whether this PdfTextBoxField is password field.

public bool Password { get; set; }

Property Value

bool

true if password field; otherwise, false.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.Password = true;
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.Password = True
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

Scrollable

Gets or sets a value indicating whether this PdfTextBoxField is scrollable.

public bool Scrollable { get; set; }

Property Value

bool

true if scrollable; otherwise, false.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.Scrollable = true;
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.Scrollable = True
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

SpellCheck

Gets or sets a value indicating whether to check spelling.

public bool SpellCheck { get; set; }

Property Value

bool

true if check spelling; otherwise, false.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.SpellCheck = true;
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.SpellCheck = True
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

Text

Gets or sets the text in the text box.

public string Text { get; set; }

Property Value

string

The text of the text box field.

Examples

//Create a new PDf document
PdfDocument document = new PdfDocument();           
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a text box
PdfTextBoxField firstNameTextBox = new PdfTextBoxField(page, "firstNameTextBox");
firstNameTextBox.Text = "Cris";
firstNameTextBox.Bounds = new RectangleF(100, 20, 200, 20);
firstNameTextBox.Font = font;
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55);
//Add the textbox in document
document.Form.Fields.Add(firstNameTextBox);                      
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a text box
Dim firstNameTextBox As PdfTextBoxField = New PdfTextBoxField(page, "firstNameTextBox")
firstNameTextBox.Text = "Cris"
firstNameTextBox.Bounds = New RectangleF(100, 20, 200, 20)
firstNameTextBox.Font = font
page.Graphics.DrawString("First Name", font, PdfBrushes.Black, 10, 55)
'Add the textbox in document
document.Form.Fields.Add(firstNameTextBox)
document.Save("Form.pdf")
document.Close(True)
See Also

Methods

DrawAppearance(PdfTemplate)

Draws the appearance.

protected override void DrawAppearance(PdfTemplate template)

Parameters

template PdfTemplate

The template.

See Also

Initialize()

Initializes an instance.

protected override void Initialize()
See Also

See Also