Skip to content

Commit 672aaca

Browse files
1015083: Signature in React PDF Viewer
1 parent bfac041 commit 672aaca

6 files changed

Lines changed: 571 additions & 0 deletions

File tree

Document-Processing-toc.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,14 @@
11081108
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/import-export-form-fields/import-export-events">Import/Export events</a></li>
11091109
</ul>
11101110
</li>
1111+
<li>Signature
1112+
<ul>
1113+
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/signature/add-handwritten-or-electronic-signature">Add Handwritten or Electronic Signature</a></li>
1114+
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/signature/add-digital-signature-react">Add Digital Signature</a></li>
1115+
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/signature/customize-signature-appearance">Customize Signature Appearance</a></li>
1116+
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/signature/validate-digital-signatures">Validate Digital Signature/a></li>
1117+
</ul>
1118+
</li>
11111119
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/custom-data">Add custom data in form fields</a></li>
11121120
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/group-form-fields">Grouping form fields</a></li>
11131121
<li><a href="/document-processing/pdf/pdf-viewer/react/forms/form-constrain">Form Field Flags</a></li>
53.4 KB
Loading
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
layout: post
3+
title: Add Digital Signature to PDF in React PDF Viewer | Syncfusion
4+
description: Learn how to add signature fields and apply PKI-based digital signatures using Syncfusion React PDF Viewer and JavaScript PDF Library.
5+
platform: document-processing
6+
control: PdfViewer
7+
documentation: ug
8+
---
9+
10+
# Add Digital Signature to PDF
11+
12+
This section explains how to **add signature fields** using the Syncfusion **React PDF Viewer** and how to apply **digital (PKI) signatures** using the **JavaScript PDF Library**.
13+
14+
N> As instructed by team leads — use the **React PDF Viewer only to add & place signature fields**. Use the **JavaScript PDF Library** to apply the *actual cryptographic digital signature*.
15+
16+
## Overview (Explanation)
17+
18+
A **digital signature** provides:
19+
- **Authenticity** – confirms the signer’s identity.
20+
- **Integrity** – detects modification after signing.
21+
- **Non‑repudiation** – signer cannot deny signing.
22+
23+
Syncfusion supports a hybrid workflow:
24+
- Viewer → **[Design signature fields](../manage-form-fields/create-form-fields#signature-field)**, capture Draw/Type/Upload electronic signature.
25+
- PDF Library → **[Apply PKCS#7/CMS digital signature](https://help.syncfusion.com/document-processing/pdf/pdf-library/javascript/digitalsignature)** using a certificate (PFX/P12).
26+
27+
## Add a Signature Field (How-to)
28+
29+
### Using the UI
30+
1. Open **Form Designer**.
31+
2. Select **Signature Field**.
32+
3. Click on the document to place the field.
33+
4. Configure Name, Tooltip, Required, etc.
34+
35+
![Signature annotation toolbar](../../../javascript-es6/images/add_sign.png)
36+
37+
### Using the API
38+
```tsx
39+
viewerRef.current?.formDesignerModule.addFormField('SignatureField', {
40+
name: 'ApproverSignature',
41+
pageNumber: 1,
42+
bounds: { X: 72, Y: 640, Width: 220, Height: 48 },
43+
isRequired: true,
44+
tooltip: 'Sign here'
45+
});
46+
```
47+
48+
## Capture Electronic Signature (Draw / Type / Upload)
49+
Users click the field → dialog appears → they can **Draw**, **Type**, or **Upload** a handwritten signature.
50+
51+
This creates a *visual* signature only (not cryptographically secure).
52+
53+
## Apply PKI Digital Signature (JavaScript PDF Library)
54+
55+
Digital signature must be applied using **@syncfusion/ej2-pdf**.
56+
57+
```ts
58+
import { PdfDocument, PdfSignature, PdfSignatureField, CryptographicStandard, DigestAlgorithm } from '@syncfusion/ej2-pdf';
59+
60+
const document = new PdfDocument(pdfBytes);
61+
const page = document.getPage(0);
62+
63+
let field = new PdfSignatureField(page, 'ApproverSignature', {
64+
x: 72,
65+
y: 640,
66+
width: 220,
67+
height: 48
68+
});
69+
document.form.add(field);
70+
71+
const signature = PdfSignature.create(
72+
{
73+
cryptographicStandard: CryptographicStandard.cms,
74+
digestAlgorithm: DigestAlgorithm.sha256
75+
},
76+
pfxBytes,
77+
password
78+
);
79+
80+
field.setSignature(signature);
81+
const signedBytes = await document.save();
82+
document.destroy();
83+
```
84+
85+
## Important Notes
86+
- **Do all form edits first. Sign last.** Any PDF modification *after signing* invalidates the signature.
87+
- Self‑signed PFX will show **Unknown / Untrusted** until added to Trusted Certificates.
88+
89+
## Best Practices
90+
- Place signature fields via Viewer for accurate layout.
91+
- Apply PKI signature using PDF Library only.
92+
- Use CMS + SHA‑256 for compatibility.
93+
- Avoid flattening **after** signing.
94+
95+
## See Also
96+
- Add Handwritten or Electronic Signature
97+
- Validate Digital Signatures
98+
- Customize Signature Appearance

Document-Processing/PDF/PDF-Viewer/react/forms/signature/add-handwritten-or-electronic-signature.md

Lines changed: 191 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
layout: post
3+
title: Customize Signature Appearance in React PDF Viewer | Syncfusion
4+
description: Learn how to customize handwritten, typed, image-based, and digital signature appearances using Signature annotations, Signature fields, and the JavaScript PDF Library.
5+
platform: document-processing
6+
control: PdfViewer
7+
documentation: ug
8+
---
9+
10+
# Customize Signature Appearance
11+
12+
This section explains how to customize the **visual appearance of signatures** in the Syncfusion **React PDF Viewer**, including:
13+
- Handwritten/electronic **Signature annotations** (Draw / Type / Upload)
14+
- **Signature field** appearance (fonts, tooltips)
15+
- **Digital signature** visual appearance (image/text via PDF Library)
16+
17+
N> This page complements: **[Add Handwritten or Electronic Signature](./add-handwritten-or-electronic-signature)**, **[Add Digital Signature](./add-digital-signature-react)**, and **[Validate Digital Signatures](./validate-digital-signatures)**.
18+
19+
## Overview (Explanation)
20+
21+
The React PDF Viewer offers two signature mechanisms:
22+
- **Signature annotation** → free‑placed electronic signature with customizable UI appearance.
23+
- **Signature field** → guided signing area inside forms; can use fonts, tooltips, and properties.
24+
- **Digital signature appearance** → applied using **[JavaScript PDF Library](https://help.syncfusion.com/document-processing/pdf/pdf-library/javascript/digitalsignature)** when generating visual PKI signature content.
25+
26+
Each supports different appearance customization levels.
27+
28+
## Customize Signature Annotation (How‑to)
29+
30+
Electronic (Draw/Type/Upload) signatures added through Annotation toolbar are fully customizable.
31+
32+
### Customize from UI
33+
Users can modify appearance through the built‑in annotation settings:
34+
- Stroke color
35+
- Line thickness
36+
- Opacity
37+
- Resizing and repositioning
38+
- Replace signature image (Upload)
39+
40+
![Signature Annotation UI](../../../javascript-es6/images/style-sign.png)
41+
42+
### Customize via API
43+
```tsx
44+
viewerRef.current.annotationModule.updateAnnotationProperties({
45+
opacity: 0.85,
46+
strokeColor: '#2C3E50',
47+
thickness: 2
48+
});
49+
```
50+
51+
## Customize Signature Field Appearance (Forms)
52+
53+
Signature fields have different customization rules. They do **not** support stroke/opacity settings like annotations.
54+
55+
### Supported customizations
56+
- Tooltip text
57+
- Name / Identifier
58+
- Required field highlight
59+
- Bounding box dimensions
60+
- **Custom font** for typed signature appearance
61+
62+
![Signature Field](../../../javascript-es6/images/ui-signature.png)
63+
64+
### Example: Adding a signature field with properties
65+
```tsx
66+
viewerRef.current?.formDesignerModule.addFormField('SignatureField', {
67+
name: 'ClientSignature',
68+
pageNumber: 1,
69+
bounds: { X: 120, Y: 620, Width: 200, Height: 48 },
70+
tooltip: 'Please sign here',
71+
isRequired: true
72+
});
73+
```
74+
75+
### Custom font for Signature Field (How‑to)
76+
Signature fields can use a custom font by embedding it inside the PDF.
77+
78+
See: **[Custom fonts for Signature and Initial fields](../../how-to/custom-font-signature-field)**.
79+
80+
## Customize Digital Signature Appearance (PDF Library)
81+
82+
When applying a PKI digital signature, you can generate a **visible signature appearance**.
83+
84+
### Example: Creating custom visible appearance
85+
```ts
86+
import {
87+
PdfDocument,
88+
PdfGraphics,
89+
PdfBitmap,
90+
PdfSignature,
91+
PdfSignatureField,
92+
CryptographicStandard,
93+
DigestAlgorithm
94+
} from '@syncfusion/ej2-pdf';
95+
96+
const doc = new PdfDocument(pdfBytes);
97+
const page = doc.getPage(0);
98+
99+
const field = new PdfSignatureField(page, 'Signer1', { x: 72, y: 640, width: 220, height: 60 });
100+
doc.form.add(field);
101+
102+
// Create graphics for appearance
103+
tconst g = field.appearance.graphics;
104+
g.drawString('Digitally Signed by User1', new PdfStandardFont(12), 0, 0);
105+
// Optional: Add an image/seal
106+
g.drawImage(new PdfBitmap(sealBytes), 120, 0, 40, 40);
107+
108+
const sig = PdfSignature.create(
109+
{ cryptographicStandard: CryptographicStandard.cms, digestAlgorithm: DigestAlgorithm.sha256 },
110+
pfxBytes,
111+
password
112+
);
113+
114+
field.setSignature(sig);
115+
const finalBytes = await doc.save();
116+
doc.destroy();
117+
```
118+
119+
### What you can customize in digital signature appearance
120+
- Text (signer name, date, labels)
121+
- Font / style
122+
- Images (company logo / seal)
123+
- Appearance bounding box
124+
- Visible vs invisible signature
125+
126+
## Best Practices
127+
- Use consistent branding colors in handwritten signatures.
128+
- Prefer **Signature fields** when you need standardized appearance.
129+
- Keep annotation opacity above **0.7** for readability.
130+
- For legally binding workflows, use **PDF Library** appearance settings.
131+
- Avoid modifying a PDF **after** applying a digital signature.
132+
133+
## See Also
134+
- [Add Handwritten or Electronic Signature](./add-handwritten-or-electronic-signature)
135+
- [Add Digital Signature](./add-digital-signature-react)
136+
- [Validate Digital Signatures](./validate-digital-signatures)
137+
- [Custom fonts for Signature fields](../../how-to/custom-font-signature-field)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
layout: post
3+
title: Validate Digital Signatures in React PDF Viewer | Syncfusion
4+
description: Learn how to validate digital signatures applied to PDF forms using the Syncfusion JavaScript PDF Library with the React PDF Viewer. Covers integrity, certificate trust, timestamp, and revocation checks.
5+
platform: document-processing
6+
control: PdfViewer
7+
documentation: ug
8+
---
9+
10+
# Validate Digital Signatures
11+
12+
This guide explains **how to validate digital signatures** on PDFs when using the **Syncfusion React PDF Viewer** together with the **JavaScript PDF Library**. It clarifies what the Viewer does (display fields and signature appearances) and what the **PDF Library** does (perform **cryptographic validation** and produce validation results).
13+
14+
N> **Important:** The React PDF Viewer renders signature fields and their visual appearances, but **cryptographic validation is performed by the JavaScript PDF Library**. Use the library to check integrity, certificate trust, and timestamp status, and surface the result in your UI.
15+
16+
## Overview (Explanation)
17+
18+
A **digital signature** is a cryptographic proof embedded in the PDF that allows verifiers to confirm:
19+
20+
- **Document integrity** – The PDF has not changed since it was signed.
21+
- **Signer identity & trust** – The signer’s certificate chains to a trusted authority or is trusted locally.
22+
- **Timestamp validity** – (If present) the signature was time‑stamped by a trusted TSA at signing time.
23+
- **Revocation status** – Whether the signer’s certificate was revoked at or after signing (OCSP/CRL).
24+
25+
In Syncfusion, you typically **[design the signature field in the Viewer](../../forms/manage-form-fields/create-form-fields#signature-field)** and then **[apply and validate the digital signature using the PDF Library]()**.
26+
27+
## How validation fits in the Viewer flow (Concept)
28+
29+
1. Load and interact with the PDF in **React PDF Viewer** (place fields, fill forms).
30+
2. Use **JavaScript PDF Library** to **open the PDF bytes** and **validate the signature**.
31+
3. Display the validation outcome (valid/invalid/unknown) in your React UI (badge, toast, side panel).
32+
33+
![Validation status badge in toolbar](../forms/images/signature-validation-badge.png)
34+
35+
## How‑to: Validate a digital signature (Client‑side)
36+
37+
The example below shows how to load the PDF bytes yourself, open with the **PDF Library**, and validate each signature field. You can call this when the document is loaded or on demand (e.g., a **Validate** button).
38+
39+
```ts
40+
// Assumes you already have the PDF bytes (e.g., fetched via fetch(...).arrayBuffer())
41+
import {
42+
PdfDocument,
43+
// The validation API is available on the signature/field instance
44+
} from '@syncfusion/ej2-pdf';
45+
46+
async function validateSignatures(pdfBytes: ArrayBuffer) {
47+
const doc = new PdfDocument(pdfBytes);
48+
49+
const results: Array<{
50+
fieldName: string;
51+
isIntact: boolean; // document integrity
52+
isTrusted: boolean; // certificate trust (based on local trust)
53+
isTimestampValid?: boolean;
54+
message: string;
55+
}> = [];
56+
57+
// Iterate form fields and locate signature fields
58+
if (doc.form && doc.form.fields && doc.form.fields.length) {
59+
for (const f of doc.form.fields as any[]) {
60+
if (f && f.type === 'SignatureField') {
61+
const sigField = f; // PdfSignatureField
62+
63+
// Validate the signature on this field. Depending on your build, this may
64+
// expose a method like validate() or properties describing status flags.
65+
// Pseudocode below: adapt to your actual API surface.
66+
const vr = await sigField.validate();
67+
// vr may include: isDocumentIntact, isCertificateTrusted, isTimestampValid, messages, etc.
68+
69+
results.push({
70+
fieldName: sigField.name,
71+
isIntact: !!vr?.isDocumentIntact,
72+
isTrusted: !!vr?.isCertificateTrusted,
73+
isTimestampValid: vr?.isTimestampValid,
74+
message: vr?.message || ''
75+
});
76+
}
77+
}
78+
}
79+
80+
doc.destroy();
81+
return results;
82+
}
83+
```
84+
85+
N> If your current build doesn’t expose a promise‑based `validate()` on the field, consult the PDF Library’s digital signature API in your version and map the available properties/methods to the same **intact / trusted / timestamp** status for display.
86+
87+
### Displaying results in React (example snippet)
88+
89+
```tsx
90+
const [validation, setValidation] = useState(null);
91+
92+
async function onValidateClick() {
93+
const bytes = await fetch('/path/to/signed.pdf').then(r => r.arrayBuffer());
94+
const r = await validateSignatures(bytes);
95+
setValidation(r);
96+
}
97+
```
98+
99+
Render a simple table or badge:
100+
101+
```tsx
102+
{validation && (
103+
<div className="sig-validation">
104+
{validation.map(v => (
105+
<div key={v.fieldName} className="chip">
106+
<strong>{v.fieldName}:</strong>
107+
{v.isIntact && v.isTrusted ? ' Valid' : ' Invalid/Unknown'}
108+
</div>
109+
))}
110+
</div>
111+
)}
112+
```
113+
114+
## Interpreting validation outcomes (Reference)
115+
116+
- **Valid** – Integrity OK **and** certificate is trusted. (Timestamp valid if present.)
117+
- **Invalid** – Bytes changed after signing **or** signature object malformed.
118+
- **Unknown/Not Trusted** – Integrity OK but signer certificate is not trusted locally (common with **self‑signed PFX** used for demos). Import the signer certificate into the trusted store to see a *Valid* badge.
119+
120+
## Best practices (Explanation)
121+
122+
- **Single‑save rule:** Do **all edits first**, then **sign**, and **do not modify** the PDF after signing; modifying bytes after signing will invalidate the signature.
123+
- **Establish trust:** For demos, a self‑signed PFX will appear *Unknown*. For production, use a certificate that chains to a trusted CA or import the signer/issuer to the verifier’s trust store.
124+
- **Prefer timestamping (TSA):** A trusted timestamp improves long‑term validation even if the signer’s cert later expires or is revoked.
125+
- **Surface status in UI:** Show a clear badge (Valid/Invalid/Unknown) near the signature field or toolbar, and offer a *View details* panel with integrity, trust, and timestamp info.
126+
127+
## Troubleshooting
128+
129+
- **Signature shows Invalid** – Check whether the PDF was modified **after** signing (e.g., second save/flatten). Re‑sign as the last step.
130+
- **Unknown signer** – You are using a **self‑signed** PFX. Import the certificate into the validator’s trust store or use a CA‑issued certificate.
131+
- **Algorithm unsupported** – Use CMS/PKCS#7 with SHA‑256 (avoid SHA‑1).
132+
- **No revocation info** – Ensure OCSP/CRL endpoints are reachable by the validator or embed revocation data if supported.
133+
134+
## See also
135+
- [Add Digital Signature](/document-processing/pdf/pdf-viewer/react/forms/signature/add-digital-signature)
136+
- [Add Handwritten or Electronic Signature](/document-processing/pdf/pdf-viewer/react/forms/signature/add-electronic-signature)
137+
- [Customize Signature Appearance](./customize-signature-appearance)

0 commit comments

Comments
 (0)