---
title: "A signing flow — Angular"
description: "Send one document to several signers. Place each signer's fields in their own color, let each fill in and sign only theirs, guide them to what's left, and seal each part with one signature."
framework: "Angular"
other_frameworks:
  "React": "https://www.cloudpdf.com/docs/headless/react/forms/signing-flow.md"
  "Vue": "https://www.cloudpdf.com/docs/headless/vue/forms/signing-flow.md"
  "Svelte": "https://www.cloudpdf.com/docs/headless/svelte/forms/signing-flow.md"
source: "https://www.cloudpdf.com/docs/headless/angular/forms/signing-flow"
---

# A signing flow

A contract goes to two people. Dana fills in her part and signs it, then Lanternfield's director
does the same. Each works in their own browser, sees which fields are theirs, and can change nothing
else. This page builds that from start to finish, with parts the other form pages describe one by
one.

Three kinds of people use your app:

| Who           | Does                                        | Uses                                                                                                                 |
| :------------ | :------------------------------------------ | :------------------------------------------------------------------------------------------------------------------- |
| The sender    | Places each signer's fields on the document | [Design mode](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#design-mode), with the signers listed |
| Each signer   | Fills in their own fields and signs         | The form layer, with permissions for their own fields                                                                |
| Anyone, later | Checks who signed, and that nothing changed | [Check the signatures](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#check-the-signatures)      |

## Name the signers

Every field belongs to a **group**, and each signer gets the permissions for one group; see
[Signers and groups](https://www.cloudpdf.com/docs/engine/forms/groups.md). The PDF holds only the group's id. Who that is, and
which color shows their fields, is your app's to say, for each document it opens:

**`name-groups.ts`**

```typescript
import { Component, effect, inject, input } from '@angular/core';
import { EpdfForm, type FormGroupInput } from '@embedpdf/angular/form';

/** Render it where the document shows, so every document you open gets its own list. */
@Component({ selector: 'app-signers', template: '' })
export class Signers {
  readonly signers = input.required<FormGroupInput[]>();

  private readonly form = inject(EpdfForm);

  constructor() {
    effect(() => this.form.setGroups(this.signers()));
  }
}
```

Give the sender's page and each signer's the same list, and everyone sees the same colors.
[Fields for several people](https://www.cloudpdf.com/docs/headless/angular/forms.md#fields-for-several-people) has every detail.

## The sender places the fields

In [design mode](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#design-mode) the sender picks who the next fields are for, then a tool,
and clicks on the page:

**`sender-toolbar.ts`**

```typescript
import { Component, inject } from '@angular/core';
import { EpdfForm } from '@embedpdf/angular/form';
import { EpdfInteraction } from '@embedpdf/angular/interaction';

@Component({
  selector: 'app-sender-toolbar',
  template: `
    @for (group of form.groups(); track group.id) {
      <button
        [attr.aria-pressed]="form.designGroup() === group.id"
        [disabled]="!form.canSetGroup(group.id)"
        (click)="form.setDesignGroup(group.id)"
      >
        <i [style.background]="group.color"></i> {{ group.label ?? group.id }}
      </button>
    }

    @for (tool of tools; track tool.id) {
      <button
        [attr.aria-pressed]="interaction.activeToolId() === tool.id"
        (click)="interaction.activateTool(tool.id)"
      >
        {{ tool.label }}
      </button>
    }
  `,
})
export class SenderToolbar {
  protected readonly form = inject(EpdfForm);
  protected readonly interaction = inject(EpdfInteraction);

  protected readonly tools = [
    { id: 'form-text', label: 'Text' },
    { id: 'form-checkbox', label: 'Checkbox' },
    { id: 'signer-signature', label: 'Signature' },
  ];
}
```

`setDesignGroup()` says who the next fields are for. The signing tools place fields that know
what they're for:

| Tool                 | Places                   | The signer                           |
| :------------------- | :----------------------- | :----------------------------------- |
| `signer-signature`   | The place they sign      | Draws, types or uploads a signature  |
| `signer-initials`    | A box for their initials | Does the same for their initials     |
| `signer-name`        | Their name               | Types nothing: your app knows it     |
| `signer-email`       | Their email address      | Types nothing                        |
| `signer-date-signed` | The day they signed      | Types nothing: it's written for them |

Each places a field with a [`purpose`](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#what-a-field-is-for), required but for the day of
signing. Every other field tool works too, such as a checkbox for "I agree".
[Place fields for a signer](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#place-fields-for-a-signer) has a live example, and
[Form tools and signing tools](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#form-tools-and-signing-tools) lists every tool.

- **One signature field per signer.** It's the one place their digital signature goes. Their
  initials, and any other place their mark shows, are [image fields](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#image-fields),
  which their signature covers.
- **On a scan saved sideways,** turn the page first: fields are placed
  [the way the sender sees it](https://www.cloudpdf.com/docs/headless/angular/forms/building.md#on-a-turned-page).
- **Placing fields for other people takes a permission** for each group:
  `fields:set-group:group=buyer`. `form.canSetGroup('buyer')` says whether the sender has it.

When the sender is done, [save the document](https://www.cloudpdf.com/docs/headless/angular/documents/saving.md). The fields are in the PDF, with
each one's group, purpose and required flag.

## Open it for a signer

Each signer opens the same document, with who they are and the permissions for their own group.
The signature plugin is in `'finish'` mode, with the key that signs:

**`plugins.ts`**

```typescript
import { Component } from '@angular/core';
import { withForm } from '@embedpdf/angular/form';
import { provideEmbedPdf } from '@embedpdf/angular/runtime';
import { withSignature } from '@embedpdf/angular/signature';
import { signingKey } from './keys';
import { engine } from './pdf';

@Component({
  selector: 'app-signing',
  providers: [
    provideEmbedPdf(
      { engine },
      /* … */
      withForm(),
      // A mark placed in a signature field is drawn in: nothing is sealed until finish().
      withSignature({ signingKey, mode: 'finish' }),
    ),
  ],
  template: `<!-- … -->`,
})
export class Signing {}
```

**`signer-viewer.ts`**

```typescript
import { Component } from '@angular/core';
import { EpdfFormLayer } from '@embedpdf/angular/form';
import { EpdfRenderLayer } from '@embedpdf/angular/render';
import { EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime';
import { EpdfPageTemplate, EpdfStage } from '@embedpdf/angular/stage';
import { Guide } from './guide';
import { NextTag } from './next-tag';
import { contract, engine, features } from './setup';

@Component({
  selector: 'app-signer-viewer',
  imports: [
    EpdfDocumentGate,
    EpdfStage,
    EpdfPageTemplate,
    EpdfRenderLayer,
    EpdfFormLayer,
    Guide,
    NextTag,
  ],
  providers: [
    provideEmbedPdf(
      {
        engine,
        identity: { userId: 'u_381', displayName: 'Dana Smith', email: 'dana@example.com' },
        scope: [
          'doc.open',
          'doc.render',
          'doc.forms.read',
          'fields:fill:group=buyer',
          'fields:sign:group=buyer',
        ],
        initialDocuments: [{ source: contract }],
      },
      ...features,
    ),
  ],
  template: `
    <ng-container *epdfDocumentGate>
      <app-guide />
      <epdf-stage>
        <ng-template epdfPage>
          <epdf-render-layer />
          <epdf-form-layer />
        </ng-template>
        <app-next-tag />
      </epdf-stage>
    </ng-container>
  `,
})
export class SignerViewer {}
```

- **`fields:fill` and `fields:sign` name the group,** so Dana fills in and signs the buyer's fields
  and nothing else. The engine checks every change, so this holds whatever your UI does.
- **`identity` is where her name and email address come from** when a field asks for them.
- **Add `doc.sign` when her signature should be checkable for years.** The validation data and
  the document timestamp belong to the document, not to a group, so they take the document's own
  permission. Beside `fields:sign:group=buyer` it lets her sign no other group's field. See
  [Keep a signature checkable for years](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#keep-a-signature-checkable-for-years).

Put the same permissions and identity in each signer's token.

Every signer sees every field and every value: groups decide who changes a field, not who sees it.

## What the signer sees

With the form layer on the page, and nothing more from you:

- **Their fields stand out** in their color. Other people's fields show as the PDF has them, take
  no input, and Tab skips them.
- **An empty field says what it's for:** "Signature", "Name".
- **What your app knows is filled in when they start.** [`form.prefill()`](https://www.cloudpdf.com/docs/headless/angular/forms.md#values-the-app-already-knows)
  writes Dana's name, her email address and today's date into her own empty fields, as real
  values: she sees them, they count as filled in, and she changes them unless the field is
  read-only. Call it when the signer starts, as the guide below does.

The colors and texts are settings: see [Fields for several people](https://www.cloudpdf.com/docs/headless/angular/forms.md#fields-for-several-people).

## Guide them to what's left

`validate()` says which required fields are still empty, and `focusNext()` goes to the next one. A
bar with "2 of 5", **Next** and **Finish** is those two calls:

**`guide.ts`**

```typescript
import { Component, computed, inject } from '@angular/core';
import { EpdfForm } from '@embedpdf/angular/form';
import { FinishButton } from './finish';

@Component({
  selector: 'app-guide',
  imports: [FinishButton],
  template: `
    <div class="guide">
      {{ check().required.length - check().missing.length }} of {{ check().required.length }}
      <button
        [disabled]="check().missing.length === 0"
        (click)="form.focusNext({ required: true, empty: true, wrap: true })"
      >
        Next
      </button>
      <app-finish-button />
    </div>
  `,
})
export class Guide {
  protected readonly form = inject(EpdfForm);

  protected readonly check = computed(() => {
    this.form.fields(); // again when a field is filled in
    return this.form.validate();
  });

  constructor() {
    // The signer starts: their name, their email address and today's date are written.
    void this.form.prefill();
  }
}
```

- **A signature field counts once it holds a mark,** and the day of signing is never on the
  list: nobody types it.
- **`getFocusedField()`,** or `focusedField` in the form's state, says where the cursor is.
- **The same bar serves a plain form** nobody signs: it reads the form, not the signatures.

To point at the field itself, pin a tag to it. This one sits beside the next field to fill in:

**`next-tag.ts`**

```typescript
import { Component, computed, inject } from '@angular/core';
import { EpdfAnchored } from '@embedpdf/angular/anchored';
import { EpdfForm } from '@embedpdf/angular/form';

/** A tag beside the next required field that is still empty. */
@Component({
  selector: 'app-next-tag',
  imports: [EpdfAnchored],
  template: `
    @if (next(); as field) {
      <epdf-anchored [anchor]="anchor()" placement="left" [gap]="6" pinned>
        <button class="next-tag" (click)="form.focus(field.ref)">
          {{ field.kind === 'signature' ? 'Sign' : 'Fill in' }}
        </button>
      </epdf-anchored>
    }
  `,
})
export class NextTag {
  protected readonly form = inject(EpdfForm);

  protected readonly next = computed(() => {
    this.form.fields(); // again when a field is filled in
    return this.form.validate().missing[0] ?? null;
  });
  protected readonly anchor = this.form.widgetAnchorOf(() => {
    const next = this.next();
    return next ? (this.form.getWidgets(next.ref)[0]?.ref ?? null) : null;
  });
}
```

Put it inside `<epdf-stage>`.
[Your own form controls](https://www.cloudpdf.com/docs/headless/angular/forms/controls.md) has more: a calendar next to a date field, a tag on every
signature field, a control of your own.

## Collect the signature

A click on a signature field that isn't signed makes it the
[target](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#sign-here-in-a-form). Show your signature pad, and place what the signer made:

```ts
const field = signature.getTarget();
if (field) {
  // or { assetId }, from their signature library
  await signature.placeMark({ source: png }, { field });
}
```

In `'finish'` mode the mark is drawn into the field and nothing is sealed yet:

- **Another mark takes its place.** A click on the field makes it the target again.
- **`signature.clearField(field)` takes it out,** and the field is on the list of what's left
  again.
- **Each is one step to undo,** with the history plugin.

[A person's signatures](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#a-persons-signatures) keeps a signature and initials to use
again.

## Finish

One call seals the signer's part:

**`finish.ts`**

```typescript
import { Component, inject } from '@angular/core';
import { EpdfForm } from '@embedpdf/angular/form';
import { EpdfSignature } from '@embedpdf/angular/signature';
import { askConsent, showProblems } from './dialogs'; // your own

@Component({
  selector: 'app-finish-button',
  template: `
    <!-- Nothing here is this person's to sign, or they finished already. -->
    @if (signature.canFinish()) {
      <button [disabled]="signature.busy()" (click)="finish()">Finish</button>
    }
  `,
})
export class FinishButton {
  private readonly form = inject(EpdfForm);
  protected readonly signature = inject(EpdfSignature);

  protected async finish() {
    if (!(await askConsent())) return;

    const result = await this.signature.finish();
    if (result.status === 'incomplete') {
      showProblems(result.missing, result.invalid);
      const first = result.missing[0] ?? result.invalid[0]?.field;
      if (first) this.form.focus(first.ref);
    }
  }
}
```

`finish()` does, in this order:

1. **Picks the signer's signature field:** the one they may sign and haven't signed.
2. **Writes the day of signing** into their `date-signed` fields, so a rule of the form that
   reads it is asked with today's date.
3. **Writes what they're still typing,** so a box the cursor hasn't left is part of it.
4. **Checks their fields:** every required one is filled in, every value passes the form's own
   rules, and the signature field holds a mark. If not, nothing is signed and it resolves
   `{ status: 'incomplete' }` with what is `missing` and what is `invalid`.
5. **Asks for your `signingKey`.**
6. **Has the engine prepare the signing.** From here it takes no change, from anyone.
7. **Checks once more,** the form the engine prepared, with what changed while the signer was
   asked for a PIN.
8. **Signs their signature field** with the key, keeping the mark they placed.
9. **Adds the validation data and the document timestamp,** when the plugin has them set.

The signature covers everything up to step 8, the date among it, and locks the signer's group:
every field in it is final, in this viewer and in every other PDF app.

- **Ask for consent before you call it.** What the signer agrees to is your app's text, not the
  viewer's.
- **`canFinish()` says whether there's a field for this person to sign.** It's `false` once they
  finished, and for someone who only looks.
- **The day of signing is the day they finish.** `prefill()` wrote the day they started; a
  signer who comes back later signs today's date.
- **Nothing else is written.** A name they changed stays as they left it, and a field they
  emptied stays empty.

[Sign as the last step](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#sign-as-the-last-step) has every detail: what `finish()`
resolves, what it rejects with, and what the file holds when the key fails.

## The next signer

The engine doesn't order the signers: your server does, by giving the next person their permissions
when the one before is done. The seller then opens the document, sees Dana's fields filled in and
locked, and goes through the same steps for theirs.

When the last one has finished, [every signature can be checked](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#check-the-signatures),
by this viewer and by Acrobat.

## Good to know

### What's in the PDF

| In the PDF, for every app                             | In your app only               |
| :---------------------------------------------------- | :----------------------------- |
| Each field's group, purpose, required flag and format | A group's `label` and `color`  |
| The values, the pictures and the signatures           | The texts an empty field shows |

Another PDF app shows the fields as plain form fields, and checks the signatures as it does any.

### Fill in first, sign once

A signature seals the document as it is. That's why a signer fills in everything and signs last,
with one signature: a field filled in after their signature would be a change to what they signed.

### A form with no groups

One person fills in a form and signs it the same way: `'finish'` mode, a mark, `finish()`. With no
groups, `finish()` locks every field in no group that holds a value, the day of signing among
them. What's still empty stays open, and so does every other signature field: a second person
fills in the rest and signs theirs, and both signatures hold.

To lock everything, say so. The other signature fields are locked then too, so nobody signs
after it:

```ts
await signature.finish({ lock: { action: 'all', fields: [] } });
```

[Sign as the last step](https://www.cloudpdf.com/docs/headless/angular/forms/signatures.md#sign-as-the-last-step) says what holds a value, and how a
call names its own lock.

### Without a key

`finish()` needs a `signingKey`. For a flow where a drawn signature is enough, leave the signature
plugin in `'visual'` mode and use `form.validateValues()` and `form.prefill()` yourself; see
[Check the values too](https://www.cloudpdf.com/docs/headless/angular/forms.md#check-the-values-too) and
[Values the app already knows](https://www.cloudpdf.com/docs/headless/angular/forms.md#values-the-app-already-knows).

### Turn pages before the first signature

A page turned after someone signed is a change to a signed document. Turn scanned pages upright
while the sender prepares the document.
