Ask Anvil

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

How do I add an initials box to every page of a PDF before sending it for signature?

You have a multi-page agreement and each page needs the signer's initials. Instead of placing each box by hand, loop over the pages and add one form field per page. This Node.js example uses pdf-lib:

const { PDFDocument, StandardFonts } = require('pdf-lib');
const fs = require('fs');

async function addInitialsBoxes(inputBytes) {
  const pdf = await PDFDocument.load(inputBytes);
  const form = pdf.getForm();
  const font = await pdf.embedFont(StandardFonts.Helvetica);

  pdf.getPages().forEach((page, i) => {
    const { width } = page.getSize();
    const field = form.createTextField(`initials_page_${i + 1}`);
    field.addToPage(page, { x: width - 90, y: 20, width: 60, height: 24 });
    page.drawText('Initials', { x: width - 90, y: 48, size: 8, font });
  });

  return pdf.save();
}

module.exports = { addInitialsBoxes };

The same function works for a 3-page or a 30-page PDF, because it reads each page's own width instead of assuming one paper size. Each box gets a unique name (initials_page_1, initials_page_2, and so on), so you can tell later which page a value came from.

Why each field needs a unique name

In pdf-lib, createTextField throws an error if a field with that name already exists. Reusing one name for every page does not work, and giving each page its own name is also what lets you read the values back individually.

Caveats

These are ordinary text fields, not signature fields. They give the signer a place to type, but they carry no signing logic of their own. If you send the PDF to an e-signature service, check how it treats existing form fields, because some services expect you to place their own initials fields through their API instead.

Adjust x, y, width and height to fit your layout, and watch for page content near the bottom edge, since the box can overlap a footer.

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
Marketing Mode