EmbedPDF

Forms & signatures

A PDF with a form can be filled in as soon as it opens: text fields, checkboxes, radio buttons, lists, and the form’s own checks and calculations. The values are saved in the file when it’s downloaded, so they open the same in Acrobat.

Read and fill in values from code#

viewer.get('form') is the form plugin. Fill in what you already know, and read what people entered:

const form = viewer.get('form');
 
await form.importValues({
  'customer.name': 'Ada Lovelace',
  'customer.email': 'ada@example.com',
});
const values = await form.exportValues(); // { 'customer.name': 'Ada Lovelace', … }

onValueChanged fires for every change, from people or from your code. See Filling forms for every method.

Loading live preview…

import { useState } from 'react';
import { PDFViewer, type Viewer } from '@embedpdf/viewer-react';

import './values.css';

const forms = 'https://www.embedpdf.com/pdfs/forms.pdf';

export default function App() {
  const [values, setValues] = useState('{}');

  // Once the form is open: show its values as they change, and fill in what the app knows.
  function onReady(viewer: Viewer) {
    viewer.documents.onOpened(async () => {
      const form = viewer.get('form');
      form.onValueChanged(() => setValues(JSON.stringify(form.exportValues())));
      await form.importValues({ name: 'Ada Lovelace', email: 'ada@example.com' });
    });
  }

  return (
    <div className="app">
      <PDFViewer src={forms} onReady={onReady} className="viewer" />
      <footer className="values">
        <span className="label">exportValues()</span>
        <code className="code">{values}</code>
      </footer>
    </div>
  );
}

Try it: the name and email came from importValues() as the form opened. Pick a plan and tick the terms: the values under the viewer follow.

Take people to a field#

Tab and Shift+Tab move through the fields in the document’s order, from page to page, and the view follows. From code, focus() brings a field into view and puts the cursor in it, and focusNext() goes on as Tab does:

const { valid, missing } = form.validate();
if (!valid) form.focus(missing[0].ref);
 
form.focusNext({ empty: true, wrap: true }); // the next field that still needs an answer

See Move between fields.

Build a form#

Building forms starts off: people fill in a form but can’t change its fields. Turn it on, and the Form mode joins the tabs:

{ features: { 'forms.building': true } }

The Form mode opens for filling in and looking. Its Form design button switches design on: then fields can be selected, moved, resized and deleted, and the form design sidebar opens. Picking one of the field tools switches design on too: drag a box where the text field, checkbox, radio button, dropdown, list or signature field goes. Press Form design again, or leave the Form mode, and the fields fill in again.

The form design sidebar holds what a field is: with nothing selected it lists the document’s fields by page, and a click on one selects it and scrolls to it; with a field selected, it shows the field’s name, tooltip, options and the rest of its settings. A radio group and a checkbox list their buttons there, with Add a button (or Add a box): the new one joins the group, below the last if they stand in a column or beside it if in a row, at the same size and spacing, and it’s selected so you can drag it. A radio group’s new button is a new choice; a checkbox’s new box checks together with the others. How a field looks, its border, background and font, is in the Style sidebar, the toolbar’s other button.

On a page that is shown turned, such as a scan saved sideways, a new field is placed the way you see the page, and what’s typed into it reads upright there. A selected field’s menu has Rotate clockwise, which turns the field a quarter turn and keeps it on the page: a field near the page’s edge lands against the edge. The Style sidebar has Orientation, which turns only what’s in the field and leaves its box where it stands. A field turns by quarter turns, the one turn a PDF form field can hold, so every PDF app shows it the same way.

Duplicate (Ctrl/Cmd+D) copies the selected fields beside the originals and selects the copies, as one step to undo. What a copy becomes follows from what was selected:

  • A radio button’s copy joins its group as a new choice. Place one button, duplicate it twice, and you have a group of three.
  • Any other field’s copy is a new field, named after the original: email becomes email_2. It has the original’s settings and no answer.

To copy a whole radio group, select one of its buttons and press Duplicate group in the sidebar: the copy is a new group with the same buttons and the same values.

For a form people fill in and can’t otherwise change, use { readOnly: { except: ['forms.filling'] } }: see Read-only.

Form settings#

{
  plugins: {
    form: { validation: 'none', focus: { color: '#7c3aed' } },
  },
}

validation: 'none' accepts every value without running the form’s own checks. Every setting is on Filling forms.

Signatures#

In the Insert mode, the signature button opens the signatures panel: one row per person, with their drawn, typed or uploaded signature and, if they want, their initials. People pick a mark and click a signature field to sign it, or click anywhere else to place it as a stamp. A click on an unsigned field starts there: the next mark picked goes in.

What signing does depends on whether you give the viewer a key:

{
  plugins: {
    signature: {
      // your key, a signing service, or one kept in the browser
      signingKey: () => mySigningService.signer(),
      // a timestamp with every signature, from your timestamp authority
      timestampAuthority: httpTimestampAuthority({ url: '/api/timestamp' }),
      // keep each signature checkable for years, with no network
      revocation: httpRevocationSource({ url: '/api/revocation' }),
      documentTimestamp: true,
      trust: { anchors: async () => [rootCertificate] },
      mode: 'ask',
      allowCertify: true,
      kinds: ['signature'], // no initials
      fonts: [{ key: 'great-vibes', url: '/fonts/GreatVibes.ttf', label: 'Great Vibes' }],
    },
  },
}
SettingWhat it doesDefault
signingKeyThe signer, or a function that returns one when someone signsnone: a mark is only drawn into the field
mode'sign' seals the document, 'visual' only draws, 'ask' shows a dialog first'sign' with a key, else 'visual'
timestampAuthorityThe timestamp authority: every signature the viewer seals carries its timestampnone
revocationWhere revocation answers come from: every signature the viewer seals gets its validation data right after. Needs trustnone
documentTimestampAdd a document timestamp after the validation data. Needs timestampAuthorityfalse
trustThe certificates you trust: for checking signatures, and for the timestamps the viewer sealsnone
allowCertifyLet the first signature be a certification, which sets what may still change: comments, form filling only, or nothingfalse
kindsWhich marks people keep: 'signature', 'initials'both
fontsFonts for typed signaturesAllura, Great Vibes and Caveat

kinds and fonts are the viewer’s; the others are the signature plugin’s.

Check signatures#

A click on a signed field shows its verdict: whether the document is unchanged since it was signed, whether the signature is valid, whether you trust the signer, and what changed since. It offers the signed revision as a download. For a signature with a timestamp, it shows the time the timestamp authority vouches for and the authority’s name, beside the time the signer claims. The panel also says what a save would do: after an unsaved annotation, an approval signature reads “valid; unsaved changes will invalidate it”, the way Acrobat warns.

Two more lines say how the signature will hold up:

  • Revocation says whether the signer’s certificate was withdrawn, when the file holds an answer: “Not revoked” or “Revoked”.
  • Long-term validation says whether the file holds everything a reader needs to check the signature with no network: “Enabled”, with the day that proof runs out, or “Not enabled”, with what is missing. For a signature that isn’t enabled, Add verification information asks for the answers and stores them. It shows when revocation and trust are set and the person may sign.

viewer.get('signature') gives you the same from code: see Signatures.

Good to know#

Where keys live#

personalSigner() keeps one self-signed identity per person in the browser’s storage, which is enough for a signature that proves the document hasn’t changed. For a signature people outside your app trust, use your own key with webCryptoSigner() or a signing service with remoteSigner(). All three come from your viewer package.

Timestamps#

A signature says when it was made by the signer’s own clock. With timestampAuthority, a timestamp authority vouches for that time, and the signature can still be checked after the signer’s certificate expires. httpTimestampAuthority() comes from your viewer package. Most authorities can’t be called from a web page, so its url is a route of your own that passes the request on: see Reach the authority from a browser.

A timestamp is never skipped: when the authority can’t be reached, the sign dialog says so and nothing is signed. With trust set, the viewer also refuses a timestamp from an authority your trust doesn’t cover; list the authority’s root under timestampAnchors.

Signatures that last#

A certificate can be withdrawn before its end date, and its issuer stops answering questions about it once it expires. With revocation, the viewer asks while the issuer still answers and keeps the answers in the file, right after each signature it seals. Acrobat shows such a signature as “LTV enabled”. With documentTimestamp too, a document timestamp follows, which proves the answers were in the file by then.

httpRevocationSource() comes from your viewer package, and its url is a route of your own: see Reach the issuers from a browser.

The signature is sealed before the answers are asked for. When they can’t be had, the document is still signed: the sign dialog says “Signed. The verification information could not be added”, and the signature’s details offer to add it later. Opening a document asks nobody: the viewer checks signatures with what the file holds.

Forms that run scripts#

A form’s own JavaScript, for checks and calculations, runs in a sandbox with no access to your page. It can’t open windows, fetch anything or read cookies.

Was this page helpful?

Your feedback goes directly to the documentation team.