Single-Line Field to Multi-Line Field

Contents
[ ]

PDF forms sometimes contain text fields designed for single-line input, which may not be sufficient for certain types of data. With Aspose.PDF for Python, developers can easily convert such fields into multi-line text fields without recreating them.

Using the FormEditor class, developers can modify existing text fields without affecting their position or other properties.

  1. Load the existing PDF document.
  2. Create a FormEditor instance.
  3. Bind the PDF document to the editor.
  4. Convert the selected field to multi-line.
  5. Save the updated document.
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


def single2multiple(infile, outfile):
    # Create FormEditor object
    form_editor = pdf_facades.FormEditor()
    # Bind document to FormEditor
    form_editor.bind_pdf(infile)
    # Change a single-lined text field to a multiple-lined one
    form_editor.single_2_multiple("City")
    # Save updated document
    form_editor.save(outfile)