Skip to content

Guides

Fillable PDF forms, flat PDFs and generated PDFs: which one do you need?

How to tell a fillable AcroForm from a flat or scanned PDF, what flattening changes, where XFA fits, and when to generate a filled PDF from a template instead.

Updated 11 min readSublimePDF Team

"Fill in this PDF" can mean four different jobs. You might be typing into the form fields of a fillable form, locking those answers into the page (flattening), placing text on top of a page that has no fields, or generating a finished document from data so that nobody fills anything in. Each needs a different tool, and choosing the wrong one is how people end up with forms that lose their answers, invoices that cannot be searched, or hours spent lining up text boxes on a scan.

This guide shows how to tell which kind of PDF you have and which approach fits. We built and inspected a set of sample files to check each claim. You can download them below.

The sample files

FileWhat it isForm fieldsValues found by text extractionSize (bytes)
sample-fillable-form.pdfBlank AcroForm made with pdf-lib: 3 text fields (one multiline), a dropdown, a radio group, a checkbox6n/a (empty)9,057
sample-form-filled.pdfThe same form with values set6, still editableNone of 510,763
sample-form-flattened.pdfThe filled form after flattening04 of 510,519
sample-form-flat-scan.pdfThe filled form as a simulated scan: one grayscale image, 200 dpi0None (no text at all)316,484
invoice.pdfSample invoice generated from a template and JSON data04 of 4 checked63,998

All names and data are fictional. "Values found by text extraction" means PDF.js getTextContent() returned the filled value as page text. That matters for search, indexing, copy and paste, and for AI tools that read PDFs as text.

How to tell what kind of PDF you have

In a viewer: click where an answer should go. If a cursor appears in a box, or the viewer offers to highlight fields, the file has interactive fields. If nothing happens, it is a flat PDF. If you cannot select any of the printed text either, it is probably a scan, an image with no text layer.

In code: ask a PDF library for the form fields, and ask a text extractor for the page text. This is the check our test script ran, using pdf-lib and PDF.js:

import fs from "node:fs/promises";
import { PDFDocument, PDFName, PDFDict } from "pdf-lib";
import * as pdfjs from "pdfjs-dist/legacy/build/pdf.mjs";
 
const bytes = await fs.readFile(process.argv[2]);
const doc = await PDFDocument.load(bytes);
const hasAcroForm = doc.catalog.lookup(PDFName.of("AcroForm")) instanceof PDFDict;
const fields = doc.getForm().getFields().map((f) => `${f.constructor.name} ${f.getName()}`);
 
const pdf = await pdfjs.getDocument({ data: new Uint8Array(bytes) }).promise;
let chars = 0;
for (let n = 1; n <= pdf.numPages; n++) {
  const page = await pdf.getPage(n);
  chars += (await page.getTextContent()).items.map((i) => i.str).join("").length;
}
console.log({ hasAcroForm, fields, textChars: chars });

Read the result like this:

  • Fields listed: a fillable AcroForm. Fill it.
  • No fields, but plenty of text: a flat digital PDF. You can add text on top, author fields, or recreate the document.
  • No fields and no text: a scan or other image-only PDF. Think about OCR or recreating the form before you try to fill it.

Go by the field list, not the /AcroForm flag alone. Our flattened sample still reported hasAcroForm: true with zero fields and 536 characters of text. The scan reported no fields and 0 characters. The script is in the repository as scripts/research/forms/detect.mjs, with its output for every sample file next to it.

Fillable forms (AcroForm)

The PDF standard calls these interactive forms. ISO 32000-1 (section 12.7.1) describes one as "a collection of fields for gathering information interactively from the user". Each field has a name, a type (text, checkbox, radio button, choice list, signature) and a value. It also has one or more widget annotations: the boxes you see on the page, with an appearance that shows the current value.

Filling a form sets the field values and updates those appearances. Our script filled the sample form with pdf-lib:

const doc = await PDFDocument.load(await fs.readFile("sample-fillable-form.pdf"));
const form = doc.getForm();
form.getTextField("applicant.name").setText("Jordan Example");
form.getTextField("applicant.email").setText("jordan@example.com");
form.getDropdown("session").select("Afternoon (14:00)");
form.getRadioGroup("ticket.type").select("student");
form.getTextField("notes").setText("Vegetarian lunch, please. Step-free access to the room.");
form.getCheckBox("consent.terms").check();
await fs.writeFile("sample-form-filled.pdf", await doc.save());

Reading the filled file back with pdf-lib returned all six values. Text extraction found none of them. PDF.js returned the same 18 text items as for the blank form: the labels, but not the answers. The answers live in the fields and their widget appearances, not in the page's text content.

What that means in practice:

  • A filled but unflattened form looks complete in a viewer but may be invisible to text search, document indexing, or a pipeline that extracts text before sending it to an AI model.
  • Anyone who opens the file can change the answers, which is useful for a draft and a problem for a record.
  • How a value looks depends on the stored appearance. A form can also set NeedAppearances, a flag that asks the viewer to build appearances itself, so different viewers may show different results. None of our sample files set it.

Flattening

Flattening turns field appearances into ordinary page content and removes the fields. According to the pdf-lib documentation, form.flatten() makes the widget appearances "part of their page's content stream", and the fields "can no longer be accessed or edited."

After flattening our filled sample:

  • pdf-lib reported 0 fields.
  • Text extraction found 4 of the 5 text values: name, email, session and notes. The fifth, the radio choice "student", is stored as a selection, not text, so only the filled circle shows it. If a choice must be searchable, print it as text as well.
  • The file got slightly smaller: 10,519 bytes against 10,763.
  • The page still listed 8 annotation references that no longer pointed to any object, and an empty /AcroForm dictionary remained. qpdf --check reported no errors, so this is harmless, but it shows that "flattened" does not always mean "every trace of the form removed". If that matters, inspect the output.

Flatten when the form is finished: when you send a completed application, archive a signed-off record, or need the values to show up in text search. Do not flatten a form someone else still has to complete. Flattening is not a security control either. A flattened page can still be edited with a PDF editor, like any other page.

Flat PDFs and scans

A flat PDF has no fields. You have three choices.

  1. Add text on top. Place text boxes over the blank lines. This works for a one-off and is what the Edit PDF tool does. It is fragile for anything repeated: positions are fixed, long answers do not wrap into the next line, and nothing marks a box as "the name field".
  2. Author fields. Use a form-authoring tool to draw fields onto the page once, then fill the result like any AcroForm. This is the right choice when you must keep the exact document, for example an official form you received from someone else.
  3. Recreate the document. If you own the form, rebuild it as a template and generate the filled version (see below).

Can a Word document become a fillable PDF?

Not by exporting it alone. A word processor's PDF export describes the finished pages; do not assume that form controls in the document come through as interactive PDF fields. After exporting, run the check above. If the field list is empty, you have a flat PDF and the choices in this section apply: author fields over the exported page with form-authoring software, or, if you only need the answers, collect them with an online form and produce the PDF from the data. Our PDF vs DOCX guide explains why the export is fixed pages rather than an editable form.

A scan adds another problem: there is no text at all. Our simulated scan returned zero text items, even though the filled answers are plainly visible in the image. Before you can search it, or even locate the fields programmatically, it needs OCR. Our guide to making a PDF searchable measures how well that works. Most scanned forms are best treated as a reason to obtain or build a digital version.

XFA forms

Some forms, often from government agencies and enterprise systems, use XFA (XML Forms Architecture) instead of, or alongside, AcroForm fields. ISO 32000-1 section 12.7.8 describes XFA as form information stored in an XML stream inside the PDF.

Support outside Adobe's software is limited. pdf-lib's documentation states that it "does not support creation, modification, or reading of XFA fields", and notes that most PDFs with form fields do not use XFA.

If you receive an XFA form, fill it in software that supports XFA, or ask the sender for an AcroForm or online version. Our inspection script checks for an /XFA entry. None of our fixtures has one, because pdf-lib cannot create them, so XFA behaviour on this page is described from sources, not tested.

Generating the filled PDF from a template

If the "form" is a document you produce yourself, such as an invoice, certificate, booking confirmation, contract summary or registration receipt, you may not need a form at all. Keep the layout as a template, send the values as data, and generate a finished PDF.

The sample invoice was produced this way from the invoice template and a JSON file. It has no form fields, and every value we checked (customer name, invoice number, due date, seller email) came back from text extraction as ordinary page text. The long variant shows the other benefit: 60 line items flow onto 4 pages with a repeating table header. A form field cannot do that: its box has a fixed size, so long values have to shrink (the standard allows auto-sized text) or get cut off.

Invoice sample files

Rendered from this template and data with headless Chromium for documentation.

With SublimePDF, your code or an AI agent sends the data to the API in one of two equal ways: with the template's HTML, or with the ID of a template you saved in the app. Using the sample template.html and data.json:

# Option 1: send the HTML and the data
jq -n --rawfile html template.html --slurpfile data data.json '{html: $html, data: $data[0]}' \
| curl -sS -X POST "https://api.sublimepdf.com/v1/html-to-pdf" \
  -H "Authorization: Bearer $SUBLIMEPDF_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- -o invoice.pdf
 
# Option 2: send a saved template's ID and the data
jq '{data: .}' data.json \
| curl -sS -X POST "https://api.sublimepdf.com/v1/templates/$SUBLIMEPDF_TEMPLATE_ID/generate" \
  -H "Authorization: Bearer $SUBLIMEPDF_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- -o invoice.pdf

The data travels inside the request body, wrapped with the HTML or under a data key, rather than as the whole body. Placeholders such as {{customer.name}} and loops over line items are explained in the template variables guide, and the HTML templates and JSON data tutorial walks through both options in Node and Python. Your system computes totals and taxes, and the template only lays them out.

The trade-off: the recipient gets a finished document, not something to edit. If they need to answer questions, send a form. If they need a record of answers you already have, generate the document.

Which approach fits

SituationApproachWhy
Someone sent you a fillable form to completeFill the AcroForm, then flatten your final copy if it is going on recordKeeps the sender's exact document and puts the answers into page text
You collect answers from people in a PDFAuthor an AcroForm, or use a web form and generate a PDF afterwardsFields validate and capture structured values
An official form exists only as a flat PDFAuthor fields once, then fillKeeps the required layout, and is reusable
You produce the same document for many recordsHTML template plus data, generated by APINo field overflow, multi-page layouts, searchable text, no manual steps
You only have a scanGet a digital original, or OCR it and recreate itImage-only pages have no fields and no text
The form is XFAUse XFA-capable software, or ask for another formatMost non-Adobe libraries and viewers cannot fill it

Filling a form with SublimePDF

The Fill PDF tool fills existing AcroForm fields in the browser, with an option to flatten the result. It does not create new fields and does not support XFA forms. For documents you generate repeatedly, start from a template such as the invoice template. If you are deciding which PDF tools a small team needs day to day, see PDF tools for small business.

Sources

  1. ISO 32000-1:2008 (Adobe public copy), 12.7 Interactive Forms and 12.7.8 XFA Forms · accessed 23 November 2026
  2. pdf-lib API documentation: PDFForm (flatten, XFA support) · accessed 23 November 2026