Skip to content

Commit 79c6be2

Browse files
1012852: Add Digital Signature and Signature workflow
1 parent 7ce4eca commit 79c6be2

1 file changed

Lines changed: 214 additions & 0 deletions

File tree

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
---
2+
layout: post
3+
title: Add Digital Signature to PDF Forms in React PDF Viewer | Syncfusion
4+
description: Learn how to add signature fields and apply digital (PKI) signatures in the Syncfusion React PDF Viewer. Includes step‑by‑step guide, multi‑user signing notes, flattening, and workflow best practices.
5+
platform: React
6+
control: PdfViewer
7+
documentation: ug
8+
---
9+
10+
# Add Digital Signature
11+
12+
This guide shows how to design signature fields, collect handwritten/typed e‑signatures in the browser, and apply **digital certificate (PKI) signatures** to PDF forms using the Syncfusion React PDF Viewer and the JavaScript PDF Library. Digital signatures provide **authenticity** and **tamper detection**, making them suitable for legally binding scenarios.
13+
14+
## Overview
15+
16+
A **digital signature** is a cryptographic proof attached to a PDF that verifies the signer’s identity and flags any post‑sign changes. It differs from a simple electronic signature (handwritten image/typed name) by providing **tamper‑evidence** and compliance with standards like CMS/PKCS#7. The Syncfusion **JavaScript PDF Library** exposes APIs to create and validate digital signatures programmatically, while the **React PDF Viewer** lets you design signature fields and capture handwritten/typed signatures in the browser.
17+
18+
## Quick Start
19+
20+
Follow these steps to add a **visible digital signature** to an existing PDF and finalize it.
21+
22+
1. **Render the React PDF Viewer with form services**
23+
24+
```tsx
25+
import * as ReactDOM from 'react-dom/client';
26+
import * as React from 'react';
27+
import {
28+
PdfViewerComponent, Inject, Toolbar, Magnification, Navigation,
29+
LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
30+
Annotation, FormFields, FormDesigner
31+
} from '@syncfusion/ej2-react-pdfviewer';
32+
33+
function App() {
34+
return (
35+
<div className='control-section'>
36+
<PdfViewerComponent
37+
id="container"
38+
documentPath="https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf"
39+
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib"
40+
style={{ height: '640px' }}>
41+
<Inject services={[Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]} />
42+
</PdfViewerComponent>
43+
</div>
44+
);
45+
}
46+
47+
ReactDOM.createRoot(document.getElementById('sample')!).render(<App />);
48+
```
49+
The Viewer requires **FormFields** and **FormDesigner** services for form interaction and design, and `resourceUrl` for proper asset loading in modern setups.
50+
51+
2. **Place a signature field (UI or API)**
52+
- **UI:** Open **Form Designer** → choose **Signature Field** → click to place → configure properties like required, tooltip, and thickness.
53+
![Signature Field](../../javascript-es6/images/ui-signature-edit.png)
54+
- **API:** Use `addFormField('SignatureField', options)` to create a signature field programmatically.
55+
56+
```tsx
57+
const viewerRef = React.useRef<PdfViewerComponent>(null);
58+
59+
const onDocumentLoad = () => {
60+
viewerRef.current?.formDesignerModule.addFormField('SignatureField', {
61+
name: 'ApproverSignature',
62+
pageNumber: 1,
63+
bounds: { X: 72, Y: 640, Width: 220, Height: 48 },
64+
isRequired: true,
65+
tooltip: 'Sign here'
66+
});
67+
};
68+
```
69+
70+
3. **Apply a PKI digital signature (JavaScript PDF Library)**
71+
72+
The library provides `PdfSignatureField` and `PdfSignature.create(...)` for PKI signing with algorithms such as **SHA‑256**.
73+
74+
```ts
75+
import {
76+
PdfDocument, PdfSignatureField, PdfSignature,
77+
CryptographicStandard, DigestAlgorithm
78+
} from '@syncfusion/ej2-pdf';
79+
80+
// Load existing PDF bytes (base64/ArrayBuffer)
81+
const document = new PdfDocument(data);
82+
const page = document.getPage(0);
83+
84+
// Create a visible signature field if needed
85+
const field = new PdfSignatureField(page, 'ApproverSignature', {
86+
x: 72, y: 640, width: 220, height: 48
87+
});
88+
89+
// Create a CMS signature using a PFX (certificate + private key)
90+
const signature = PdfSignature.create(
91+
{ cryptographicStandard: CryptographicStandard.cms, digestAlgorithm: DigestAlgorithm.sha256 },
92+
certData,
93+
password
94+
);
95+
96+
field.setSignature(signature);
97+
document.form.add(field);
98+
99+
const signedBytes = await document.save('signed.pdf');
100+
document.destroy();
101+
```
102+
103+
4. **Finalize by flattening**
104+
Set `PdfDocument.flatten = true` to make annotations and form fields permanent. (The Viewer UI itself does not flatten; use the PDF Library in your pipeline.)
105+
106+
```ts
107+
import { PdfDocument } from '@syncfusion/ej2-pdf';
108+
109+
const doc = new PdfDocument(signedBytes);
110+
doc.flatten = true; // flattens annotations and form fields
111+
const finalBytes = await doc.save('final.pdf');
112+
doc.destroy();
113+
```
114+
115+
N> For sequential or multi‑user flows and digital signature appearances, see these live demos: [eSigning PDF Form](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/esigning-pdf-forms), [Invisible Signature](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/invisible-digital-signature) and [Visible Signature](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/visible-digital-signature) in the React Sample Browser.
116+
117+
## How‑to guides
118+
119+
### Add a signature field (UI)
120+
Use the Form Designer toolbar to place a **Signature Field** where signing is required. Configure indicator text, required state, and tooltip in the properties pane.
121+
122+
![Signature Field](../../javascript-es6/images/ui-signature.png)
123+
124+
### Add a signature field (API)
125+
126+
Adds a signature field programmatically at the given bounds.
127+
128+
```tsx
129+
viewerRef.current?.formDesignerModule.addFormField('SignatureField', {
130+
name: 'CustomerSign',
131+
pageNumber: 1,
132+
bounds: { X: 56, Y: 700, Width: 200, Height: 44 },
133+
isRequired: true
134+
});
135+
```
136+
137+
### Capture handwritten/typed signature in the browser
138+
139+
When users click a signature field at runtime, the Viewer’s dialog lets them **draw**, **type**, or **upload** a handwritten signature image—no plugins required—making it ideal for quick approvals.
140+
141+
![Signature Image](../images/handwritten-sign.png)
142+
143+
N> For a ready‑to‑try flow that routes two users to sign their own fields and then finalize, open [eSigning PDF Form](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/esigning-pdf-forms) in the sample browser.
144+
145+
### Apply a PKI digital signature
146+
147+
Use the **JavaScript PDF Library** to apply a cryptographic signature on a field, with or without a visible appearance. See the **Digital Signature** documentation for additional options (external signing callbacks, digest algorithms, etc.).
148+
149+
N> To preview visual differences, check the [Invisible Signature](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/invisible-digital-signature) and [Visible Signature](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/visible-digital-signature) in our Sample Browser. Digital Signature samples in the React sample browser.
150+
151+
### Finalize a signed document (flatten/lock)
152+
153+
After collecting all signatures and passing validations, **flatten** the PDF (and optionally restrict permissions) to prevent further edits. Use `PdfDocument.flatten` when saving the file.
154+
155+
## Signature Workflow Best Practices (Explanation)
156+
157+
Designing a well‑structured signature workflow ensures clarity, security, and efficiency when working with PDF documents. Signature workflows typically involve multiple participants—reviewers and approvers each interacting with the document at different stages.
158+
159+
### Why structured signature workflows matter
160+
161+
A clear signature workflow prevents improper edits, guarantees document authenticity, and reduces bottlenecks during review cycles. When multiple stakeholders sign or comment on a document, maintaining order is crucial for compliance, traceability, and preventing accidental overwrites.
162+
163+
### Choosing the appropriate signature type
164+
165+
Different business scenarios require different signature types. Consider the purpose, regulatory requirements, and level of trust demanded by the workflow.
166+
167+
- **Handwritten/typed (electronic) signature** – Best for informal approvals, acknowledgments, and internal flows. (Captured via the Viewer’s signature dialog.)
168+
169+
![Handwritten Signature](../images/handwritten-sign.png)
170+
171+
- **Digital certificate signature (PKI)** – Required for legally binding contracts and tamper detection with a verifiable signer identity. (Created with the JavaScript PDF Library.)
172+
173+
N> You can explore and try out live demos for [Invisible Signature](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/invisible-digital-signature) and [Visible Signature](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/visible-digital-signature) in our Sample Browser.
174+
175+
### Pre‑signing validation checklist
176+
177+
To prevent rework, validate the PDF before enabling signatures:
178+
- Confirm all **required form fields** are completed (names, dates, totals). (See [Form Validation](../forms/form-validation).)
179+
- Re‑validate key values (financial totals, tax calculations, contract amounts).
180+
- Lock or restrict editing during review to prevent unauthorized changes.
181+
- Use [annotations](../annotation/overview) and [comments](../annotation/comments) for clarifications before signing.
182+
183+
### Role‑based authorization flow
184+
185+
- **Reviewer** – Reviews the document and adds [comments/markups](../annotation/comments). Avoid placing signatures until issues are resolved.
186+
![Reviewer using highlights and comments](../images/highlight-comments.png)
187+
- **Approver** – Ensures feedback is addressed and signs when finalized.
188+
![Signature Image](../images/handwritten-sign.png)
189+
- **Final Approver** – Verifies requirements, then [flattens](../document-handling/preprocess-pdf#flatten-form-fields--annotations) or [Lock Signautre](https://help.syncfusion.com/document-processing/pdf/pdf-library/javascript/digitalsignature#lock-signature) to make signatures permanent and may restrict further edits.
190+
191+
N> **Implementation tip:** Use the PDF Library’s `flatten` when saving to make annotations and form fields permanent after the last signature.
192+
193+
### Multi‑signer patterns and iterative approvals
194+
- Route the document through a defined **sequence of signers**.
195+
- Use [comments and replies](../annotation/comments#add-comments-and-replies) for feedback without altering document content.
196+
- For external participants, share only annotation data (XFDF/JSON) when appropriate instead of the full PDF.
197+
- After all signatures, **flatten** to lock the file.
198+
199+
N> Refer to [eSigning PDF Forms](https://document.syncfusion.com/demos/pdf-viewer/react/#/bootstrap5/pdfviewer/esigning-pdf-forms) sample that shows two signers filling only their designated fields and finalizing the document.
200+
201+
### Security, deployment, and audit considerations
202+
203+
- **Restrict access:** Enforce authentication and role‑based permissions.
204+
- **Secure endpoints:** Protect PDF endpoints with token‑based access and authorization checks.
205+
- **Audit and traceability:** Log signature placements, edits, and finalization events for compliance and audits.
206+
- **Data protection:** Avoid storing sensitive PDFs on client devices; prefer secure server storage and transmission.
207+
- **Finalize:** After collecting all signatures, flatten or lock to prevent edits.
208+
209+
## See also
210+
- [Create and Modify Annotation](../annotation/create-modify-annotation)
211+
- [Customize Annotation](../annotation/customize-annotation)
212+
- [Digital Signature - JavaScript PDF Library](https://help.syncfusion.com/document-processing/pdf/pdf-library/javascript/digitalsignature)
213+
- [Handwritten Signature](../annotation/signature-annotation)
214+
- [Form Fields API](../form-fields-api)

0 commit comments

Comments
 (0)