Docs / Forms and signatures

Templates

Forms and signatures

DevilPDF can produce PDFs with real form fields: text boxes a reader types into, checkboxes, and signature fields. It can also fill the fields of a PDF you already have.

#Add fields to a document

Mark where each field goes with an empty link that has the class field and a data-field name. Then render with pdf.form set to true.

<h2>Consent form</h2>

<p>Full name <a class="field" data-field="full_name"></a></p>

<p><a class="field check" data-field="agree"></a> I agree to the terms.</p>

<p class="label">Comments</p>
<a class="field area" data-field="comments"></a>

<p class="label mt-3">Signature</p>
<a class="field sign" data-field="signature"></a>
curl https://devilpdf.com/v1/render \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "tpl_8sK2mQx7Lp0aVn3RtYc1",
    "data": { "customer": { "name": "Dana Whitfield" } },
    "pdf": { "form": true }
  }'

Each placeholder becomes a form field of the same size, in the same place.

#Field types

MarkupFieldLooks like
<a class="field" data-field="name"></a>Single-line textAn underline, at least 120pt wide.
<a class="field box" data-field="name"></a>Single-line textA bordered box.
<a class="field area" data-field="name"></a>Multi-line textA full-width bordered box, 64pt tall.
<a class="field check" data-field="name"></a>CheckboxA small square.
<a class="field sign" data-field="name"></a>SignatureA full-width line with room above it.

Size a field with CSS, for example style="min-width: 240pt".

#Rules

  • pdf.form must be true. Without it, the placeholders print as empty lines and boxes, which suits a form meant for pen and paper.
  • Field names can come from data: data-field="guest_{{ forloop.index }}". Dots in a name become underscores.
  • Two text fields or checkboxes with the same name are linked and share one value.
  • Fields work in templates and in raw HTML. Raw HTML needs options.kit set to true for the field styles.
  • Fields are a PDF feature. Sending pdf.form with an image format returns invalid_request.

#Signature fields

A field sign placeholder becomes an empty signature field. PDF readers that support signing, such as Adobe Acrobat, let the reader click it and sign.

DevilPDF creates the field. It does not collect signatures, send signing requests, or keep an audit trail. If you need those, send the generated PDF through an e-signature service; most of them detect the signature field.

For a line that is signed by hand on paper, use the kit's signatures block instead.

#Pre-fill fields

To produce a form that is already partly filled in, render it with fields, then fill it:

curl https://devilpdf.com/v1/pdf/fill \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "file": "doc_pCI11hgbgEyGfYeHnS5M",
    "fields": { "full_name": "Dana Whitfield", "agree": true }
  }'

#Fill any PDF form

POST /v1/pdf/fill works on any PDF with form fields, not only ones DevilPDF made. This is how you fill government forms, applications and other fixed PDFs.

FieldTypeDescription
filestringThe PDF: a document id, an https URL, or base64 content.
fieldsobjectField name → value. Text takes a string, checkboxes take true or false, dropdowns and radio groups take the option to select.
flattenbooleanMake the filled values permanent and remove the fields, so the result cannot be edited. Default false.
passwordstringThe password, if the PDF is protected.
output, filenameAs for other PDF tools.

The response is a document, plus two lists that tell you what happened:

{
  "object": "document",
  "id": "doc_Qm3xW8nLr2Kp5Vt9Yc0a",
  "status": "succeeded",
  "url": "https://devilpdf.com/f/doc_Qm3xW8nLr2Kp5Vt9Yc0a/filled.pdf?exp=1773532800&sig=72edf545dccdbebea57a43cd1e0313a4",
  "filled": ["full_name", "agree"],
  "unknown_fields": ["middle_name"]
}

unknown_fields lists the names you sent that the PDF does not have. They are skipped, not treated as an error.

#Find a PDF's field names

POST /v1/pdf/fields lists the fields in a PDF. It is free and creates no document.

curl https://devilpdf.com/v1/pdf/fields \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "file": "https://example.com/forms/application.pdf" }'
Response
{
  "object": "list",
  "data": [
    { "name": "full_name", "type": "text" },
    { "name": "agree", "type": "checkbox" },
    { "name": "signature", "type": "signature" }
  ]
}

Types are text, checkbox, dropdown, radio, list, signature or unknown.