Ask Anvil

Answers to questions about automating PDFs, e-signatures, Webforms, and other paperwork problems.
E-signatures
Categories

How do I pre-fill PDF fields before sending a document for e-signature via an API?

When you send a contract or form for signature, you usually do not want the signer retyping data you already have. The standard approach is to merge your known values into the PDF first, then route the pre-filled document for signing in the same API call. The signer sees a finished document and only completes the fields you left for them, such as a signature or a date.

Fill and send in one call

Anvil's createEtchPacket mutation does both steps at once. The files array references your PDF template, the data.payloads object pre-fills fields before the packet is sent, and the signers array attaches signature fields to each signer:

const Anvil = require('@anvilco/anvil')

const anvilClient = new Anvil({ apiKey: 'yourApiKey' })

const variables = {
  name: 'Onboarding Agreement',
  isDraft: false,
  isTest: true,
  files: [
    {
      id: 'agreement',
      castEid: '05xXsZko33JIO6aq5Pnr', // your PDF template ID
    },
  ],
  // data.payloads pre-fills the PDF before any signer sees it
  data: {
    payloads: {
      agreement: {
        data: {
          fullName: 'Jordan Lee',
          startDate: '2026-07-01',
        },
      },
    },
  },
  signers: [
    {
      id: 'employee',
      name: 'Jordan Lee',
      email: 'jordan@example.com',
      signerType: 'email',
      fields: [
        { fileId: 'agreement', fieldId: 'signature' },
      ],
    },
  ],
}

const response = await anvilClient.createEtchPacket({ variables })
const etchPacket = response.data?.data?.createEtchPacket

The keys inside data.payloads must match the file id values in the files array, and the keys inside each nested data object must match the field IDs (the field aliases) defined on the template. Anything you pre-fill here is baked into the document before it reaches the signer.

Two things to watch

Pre-filled values are not the same as signer-editable fields. If you want the signer to review and change a value, leave it out of data.payloads and attach it as a field instead. Also keep isTest set to true while you build: test packets are free and behave normally, except the output carries a watermark and red signatures. Anvil only bills a packet ($1.50 per integrated Etch e-sign packet) once every signer has finished, so unsent or incomplete packets cost nothing.

Back to All Questions

The fastest way to build software for documents

Anvil Document SDK is a comprehensive toolbox for product teams launching document flows where PDF filling, signing, and complex conditional scenarios are necessary.
Explore Anvil
Anvil Webforms