How to generate documents with fillable PDF templates (AcroForm)

Tabla de contenidos

Athento allows you to generate documents with fillable PDF templates (AcroForm): you upload a PDF that contains form fields, indicate which document data should fill each field, and Athento returns an automatically completed PDF. This functionality extends Athento’s template system (which already supports Word, Excel, HTML, and Jasper) to cover official forms or pre-printed documents that must always be filled out with the same structure.

What is a fillable PDF template (AcroForm)

A fillable PDF template is a PDF that includes AcroForm form fields: checkboxes and text boxes with an internal name, which a program can fill automatically. It is the same type of form that is filled out manually in a PDF reader, except that here Athento fills it with the document metadata.

The essential requirement is that the PDF actually contains AcroForm fields. A PDF that is only an image or plain text is not suitable, because it has no fields to write in. The fields are created with PDF editing tools (for example, editors that allow adding form fields), and each field has an internal name such as ApplicantName or ApplicantTaxID, which is the reference Athento uses.

When a PDF of this type is uploaded, Athento automatically recognizes it as a fillable PDF template type and displays the specific configuration options. If the PDF does not have AcroForm fields, Athento warns that the template is not fillable.

How the document is generated and what to keep in mind

With the template configured, the document is generated from a document of the corresponding type, using the template like the rest of Athento templates. At that moment, Athento evaluates each expression with the metadata of that document, fills the PDF fields, and returns the final PDF, which can be downloaded and viewed normally.

The slug of each metadata field is consulted in the template configuration itself. It is important that the name in braces matches the metadata slug; if a field is left blank, it is simply not filled. The names in the left column are the internal names of the PDF fields and are not modified: they come from the file itself.

If an expression fails or refers to metadata that does not exist, that specific field remains unfilled and the error is logged, but the rest of the PDF is generated anyway. If the uploaded PDF does not contain AcroForm fields, the card directly shows the warning that the template is not fillable, and it is advisable to check that the file has been created with form fields.

Table fields in Acroform PDF templates

If you put the slug of a table-type field in the field mapping, it will be printed as text, with the rows separated by line breaks, for example metadata_campo_tabla:

columna_prueba_a: valor_1; columna_prueba_b: valor_2;
columna_prueba_a: valor_3; columna_prueba_b: valor_4;

It is possible to access a table-type field as an object through its slug, adding "_rows" at the end. For example, metadata_campo_tabla_rows. This returns a list of the rows of the table with the columns as keys, for example for this case:

[
  {
    "columna_prueba_a": valor_1,
    "columna_prueba_b": valor_2
  },
  {
    "columna_prueba_a": valor_3,
    "columna_prueba_b": valor_4
  }
]

In this way, it can be included both in a Jinja expression in the mapping to a field, or you can even access a specific element of the table.

If you wanted to access the value in the first row of the column named columna_prueba_a, you could access it through metadata_campo_tabla_rows[0]['columna_prueba_a'], with 0 being the value that represents access to the first row, and then accessing the column.