Unofficial Content

Fill a form field (SetField)

Objective

Write the value of a single form field of a PDF document, identified by its name, generating a new file with that value applied. It is the symmetric functionality to GetField: while GetField reads a single field directly from the file, SetField writes it directly into the file, without needing to go through a full collection (GetFields / SetFields).

Parameters

Parameter Required Description
Source path Yes PDF (template) file whose form is filled.
Destination path Yes Path where the PDF file with the filled field will be generated.
Field Yes PDFToolsFormField item (field name / value) to fill. Its Key (field name) and Value (value to write) properties are used; Options is ignored.

Result

Operation status (Error / ErrorMessage) via PDFToolsStatus.

Functional details

  • A non-existent field is an error: if the indicated name does not exist in the document, the operation fails and no destination file is generated.

  • An invalid value is also an error: for fields with a closed set of valid values (checkbox, radio button, list/combo — see GetField), if Value is not one of those possible values, the operation fails and no destination file is generated. Text fields (and any other type without a closed set of values) accept any Value.

  • To validate beforehand which values a field accepts (for example, in a checkbox or a list/combo), first query GetField and check its possible values.

  • Case-sensitive: the field name (for example Country vs. country) is case-sensitive. If the indicated name does not exactly match the one defined in the document, it is treated as a non-existent field.

  • There is no native "date" type: the PDF forms standard only defines four field types: text, checkbox/radio button, list/combo, and signature. What often looks like a "date field" with a calendar picker in tools like Adobe Acrobat is actually a plain text field with JavaScript embedded in the document itself; this component treats any field of this kind as plain text, without validating or interpreting date formats.

  • The source file cannot be password-protected.

Usage example

&PDFFileSource            = "C:\Documents\emptyForm.pdf"
&PDFFileTarget            = "C:\Documents\filledForm.pdf"
&PDFToolsFormField.Key    = "Country"
&PDFToolsFormField.Value  = "AR"

&PDFToolsStatus = &PdfToolsUtils.SetField(&PDFFileSource,&PDFFileTarget,&PDFToolsFormField)

Error and warning messages

Situation Type Message / behavior
The indicated field name does not exist in the document Error Message indicating the field does not exist; no destination file is generated.
Value is not one of the field's possible values (checkbox, radio button, list/combo) Error Message indicating the value is invalid, including the list of valid values; no destination file is generated.
The source file does not exist, is corrupted, or is protected Error Message describing the problem reading the file.
Last update: 2026 | © GeneXus. All rights reserved. GeneXus Powered by Globant