Nutrient Python SDK
Need pricing or implementation help? Talk to Sales.
PDF FORMS IN PYTHON
from nutrient_sdk import Documentfrom nutrient_sdk import PdfEditorfrom nutrient_sdk import PdfFormFieldTypefrom nutrient_sdk import NutrientException
def main(): try: with Document.open("input_forms.pdf") as document: editor = PdfEditor.edit(document) form_fields = editor.get_form_field_collection()
text_field = form_fields.find_by_full_name("Text1") if text_field is not None: text_field.set_value("John Doe")
checkbox = form_fields.find_by_full_name("Check1") if checkbox is not None: checkbox.set_checked(True)
editor.save_as("output.pdf") editor.close() except NutrientException as e: print(f"Error: {e}")
if __name__ == "__main__": main()from nutrient_sdk import Documentfrom nutrient_sdk import PdfEditorfrom nutrient_sdk import Colorfrom nutrient_sdk import NutrientException
def main(): try: with Document.open("input.pdf") as document: editor = PdfEditor.edit(document) pages = editor.get_page_collection() form_fields = editor.get_form_field_collection()
name_field = form_fields.add_text_field( "userName", pages.get_first(), 50.0, 700.0, 200.0, 20.0 ) name_field.font_size = 12.0 name_field.font_color = Color.from_argb( 255, 0, 0, 0 )
editor.save_as("output.pdf") editor.close() except NutrientException as e: print(f"Error: {e}")
if __name__ == "__main__": main()from nutrient_sdk import Documentfrom nutrient_sdk import PdfEditorfrom nutrient_sdk import NutrientException
def main(): try: with Document.open("input_forms.pdf") as document: editor = PdfEditor.edit(document) form_fields = editor.get_form_field_collection()
field = form_fields.find_by_full_name("Text1") if field is not None: field.set_is_read_only(True) field.set_is_required(True)
editor.save_as("output.pdf") editor.close() except NutrientException as e: print(f"Error: {e}")
if __name__ == "__main__": main()USE CASES
Customer data, application details, or survey responses arrive as structured data. Fill PDF form fields automatically in a Django view, FastAPI endpoint, or background task.
Add text fields, checkboxes, dropdowns, and signature fields to existing PDFs. Build reusable form templates programmatically.
Mark fields as required for validation, set fields to read-only after submission, or inspect field properties before processing.
Iterate through form fields, fill values conditionally based on field type, and batch-process multiple documents in a single script.
Fill text fields, check checkboxes, select radio buttons, and choose dropdown and list box items programmatically.
Create form fields on existing PDF pages. Position, size, and style each field with full control.
Inspect and modify form field properties. Set fields to read-only, mark as required, and navigate field hierarchy.
ADVANCED CAPABILITIES
The SDK handles more than simple form filling. Build form processing into automated workflows and deploy anywhere Python runs.
Iterate through all form fields and fill values conditionally based on field type and read-only state.
Access parent-child field relationships using dot notation names and navigate nested field structures.
No GUI dependencies — create, fill, and edit PDF forms in background jobs, cron tasks, or API handlers.
Deploy anywhere Python runs — the SDK has no platform-specific system dependencies.
Open the PDF, create an editor, and use the form field collection to find fields by name. Set text values, check checkboxes, select radio buttons, and choose dropdown items. Save the result as a new file. See the fill PDF form guide for a complete example.
The SDK provides methods for each field type: set_value() for text fields, set_checked() for checkboxes, set_selected_option() for radio buttons, and set_selected_item() for combo boxes and list boxes. Find fields by name and fill them in any order.
The SDK supports seven field types: text fields (single-line and multiline), checkboxes, radio button groups, combo boxes (dropdowns), list boxes, push buttons with captions, and signature fields. Each field is positioned by page, coordinates, width, and height.
Open the PDF, create an editor, and use the form field collection to add fields. Each add method takes a field name, page reference, and position coordinates. You can also set font size and font color, as well as add items to combo and list boxes.
Yes. Find the field by name and call set_is_read_only(True) to lock it. You can also mark fields as required with set_is_required(True) for validation purposes. See the editing form fields guide.
The SDK is a standard Python library, so you can iterate through files in a loop. For each document, open it, fill the form fields, and save. You can also iterate through all fields in a single form and fill them conditionally based on field type.
Use the form field collection to iterate through fields and check properties like field type, name, read-only state, required state, and current value. The SDK supports hierarchical field names using dot notation for nested structures.
Wrap your code in a try-except block and catch NutrientException for SDK-specific errors. Use the context manager syntax (with Document.open(...) as document:) to ensure automatic resource cleanup, even when errors occur.
FREE TRIAL
Start creating, editing, and filling PDF forms in Python in minutes — no payment information required.
Also available for
More Python SDK capabilities