Rename Field
Contents
[
Hide
]
PDF forms often rely on field names for scripting, automation, and data processing. Using Aspose.PDF for Python, developers can rename existing fields without recreating them or altering the form layout.
The FormEditor class provides the ‘rename_field’ method, which allows developers to change the name of an existing field while preserving its position, value, and appearance.
- Load the existing PDF form.
- Create a FormEditor instance.
- Bind the PDF document to the editor.
- Rename the target field.
- Save the updated PDF.
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 rename_field(infile, outfile):
# Create FormEditor object
form_editor = pdf_facades.FormEditor()
# Bind document to FormEditor
form_editor.bind_pdf(infile)
# Rename field in document
form_editor.rename_field("City", "Town")
# Save updated document
form_editor.save(outfile)