Create TextBox Field
Contents
[
Hide
]
PDF forms often require text input from users, such as names, addresses, or comments. TextBox fields enable this functionality by providing editable fields directly within the PDF document.
The FormEditor class allows adding text fields, checkboxes, radio buttons, list boxes, combo boxes, and buttons, making it easy to build interactive PDFs.
- Load an existing PDF document.
- Add multiple TextBox fields for user input.
- Set default values for each field.
- Save the updated PDF document.
import sys
from os import path
import aspose.pdf.facades as pdf_facades
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def create_textbox_field(infile, outfile):
"""Create TextBox field in PDF document."""
pdf_form_editor = pdf_facades.FormEditor()
pdf_form_editor.bind_pdf(infile)
# Add TextBox field to PDF form
pdf_form_editor.add_field(
pdf_facades.FieldType.TEXT, "first_name", "Alexander", 1, 50, 570, 150, 590
)
pdf_form_editor.add_field(
pdf_facades.FieldType.TEXT, "last_name", "Smith", 1, 235, 570, 330, 590
)
# Save updated PDF document with form fields
pdf_form_editor.save(outfile)