Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions Document-Processing/PDF/PDF-Library/javascript/DigitalSignature.md
Original file line number Diff line number Diff line change
Expand Up @@ -884,5 +884,135 @@ var signedDocumentData = ej.pdf.PdfSignature.replaceEmptySignature(
// Destroy the document
document.destroy();

{% endhighlight %}
{% endtabs %}

## Sign existing signature field

This section explains how to sign an existing unsigned signature field in a PDF using the JavaScript PDF library. You can locate predefined signature fields and apply a digital signature directly by calling `field.setSignature()`, without altering the document layout. This is ideal for templates where signature placeholders already exist, allowing you to add digital signatures to the field using a certificate and signature settings.

{% tabs %}
{% highlight typescript tabtitle="TypeScript" %}
import {PdfDocument, PdfForm, DigestAlgorithm, CryptographicStandard, PdfSignatureField} from '@syncfusion/ej2-pdf';

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access loaded form
let form: PdfForm = document.form;
// Access the loaded form field
let field: PdfSignatureField = form.fieldAt(0);
// Create a digital signature with CMS + SHA-256
const signature: PdfSignature = PdfSignature.create(certificate, 'password', {
digestAlgorithm: DigestAlgorithm.sha256,
cryptographicStandard: CryptographicStandard.cms
});
// Apply the signature to the field
field.setSignature(signature);
// Save the document
document.save('Output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% highlight javascript tabtitle="JavaScript" %}

// Load an existing PDF document
var document = new ej.pdf.PdfDocument(data);
// Access loaded form
var form = document.form;
// Access the loaded form field
var field = form.fieldAt(0);
// Create a digital signature with CMS + SHA-256
const signature = ej.pdf.PdfSignature.create(certificate, 'password', {
digestAlgorithm: ej.pdf.DigestAlgorithm.sha256,
cryptographicStandard: ej.pdf.CryptographicStandard.cms
});
// Apply the signature to the field
field.setSignature(signature);
// Save the document
document.save('Output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% endtabs %}

## Remove existing digital signature

This section explains how to remove an existing digital signature from a PDF by using `removeField()` to delete the signature field entirely. Removing the field clears the signature dictionary, allowing the document to be edited, corrected, or re‑signed as needed. This is useful when preparing a PDF for updates or resolving signature‑related issues.

{% tabs %}
{% highlight typescript tabtitle="TypeScript" %}
import {PdfDocument, PdfForm, PdfSignatureField} from '@syncfusion/ej2-pdf';

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access loaded form
let form: PdfForm = document.form;
// Access the loaded form field
let field: PdfSignatureField = form.fieldAt(0) as PdfSignatureField;
// Remove the signature field
if (field instanceof PdfSignatureField) {
document.form.removeField(field);
}
// Destroy the document
document.destroy();

{% endhighlight %}
{% highlight javascript tabtitle="JavaScript" %}

// Load an existing PDF document
var document = new ej.pdf.PdfDocument(data);
// Access loaded form
var form = document.form;
// Access the loaded form field
var field = form.fieldAt(0);
// Remove the signature field
if (field instanceof ej.pdf.PdfSignatureField) {
document.form.removeField(field);
}
// Destroy the document
document.destroy();

{% endhighlight %}
{% endtabs %}

## Document revisions

Digital signatures create incremental revisions in a PDF, preserving each version of the document as new signatures are added. These revisions allow you to view the state of the document at the time of signing and verify whether any changes occurred afterward. The API provides access to these versions through `getRevisions()` for all revisions and `getRevision()` for the specific revision tied to a signature.

{% tabs %}
{% highlight typescript tabtitle="TypeScript" %}
import {PdfDocument, PdfForm, PdfSignatureField} from '@syncfusion/ej2-pdf';

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access loaded form
let form: PdfForm = document.form;
// Access the loaded form field
let signature: PdfSignatureField = form.fieldAt(0);
// Retrieve all revision indexes of the PDF document
let revisions: number[] = document.getRevisions();
// Gets the revision number associated with the signature field
let revision: number = signature.getRevision();
// Destroy the document
document.destroy();

{% endhighlight %}
{% highlight javascript tabtitle="JavaScript" %}

// Load an existing PDF document
var document = new ej.pdf.PdfDocument(data);
// Access loaded form
var form = document.form;
// Access the loaded form field
var signature = form.fieldAt(0);
// Retrieve all revision indexes of the PDF document
var revisions = document.getRevisions();
// Gets the revision number associated with the signature field
var revision = signature.getRevision();
// Destroy the document
document.destroy();

{% endhighlight %}
{% endtabs %}
64 changes: 64 additions & 0 deletions Document-Processing/PDF/PDF-Library/javascript/FormFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,70 @@ document. Destroy();
{% endhighlight %}
{% endtabs %}

## Add a date field to a PDF form

This section shows how to add a date field to a PDF form, allowing users to enter or select a date within the document. The JavaScript PDF library lets you configure the date field’s appearance, format, and behavior. You can use `dateField.actions` to trigger custom scripts or validations when the field is focused, changed, or submitted.

{% tabs %}
{% highlight typescript tabtitle="TypeScript" %}
import {PdfDocument, pdfPage, PdfForm, PdfTextBoxField, PdfJavaScriptAction } from '@syncfusion/ej2-pdf';

// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a new page to the document
let page: pdfPage = document.addPage();
// Access loaded form
let form: PdfForm = document.form;
// Create a new text box field
const field: PdfTextBoxField = new PdfTextBoxField(page, 'DateField', {
x: 50, y: 200, width: 150, height: 20,
});
// Sets the text value to text box field
field.text = '18/08/2003';
// Sets date formate
const format: string = 'yyyy-mm-dd';
// Add a JavaScript action to run custom scripts or validations
field.actions.format = new PdfJavaScriptAction(`AFDate_FormatEx("${format}");`);
field.actions.keyPressed = new PdfJavaScriptAction(`AFDate_KeystrokeEx("${format}"):`);
field.actions.validate = new PdfJavaScriptAction(`AFDate_Validate("${format}");`);
// Add a new form field
form.add(field);
// Save the document
document.save('output.pdf');
// Destroy the document
document. Destroy();

{% endhighlight %}
{% highlight javascript tabtitle="JavaScript" %}

// Create a new PDF document instance
var document = new ej.pdf.PdfDocument();
// Add a new page to the document
var page = document.addPage();
// Access loaded form
var form = document.form;
// Create a new text box field
const field = new ej.pdf.PdfTextBoxField(page, 'fieldF', {
x: 50, y: 200, width: 150, height: 20
});
// Sets the text value to text box field
field.text = '18/08/2003';
// Sets date formate
const format = 'yyyy-mm-dd';
// Add a JavaScript action to run custom scripts or validations
field.actions.format = new ej.pdf.PdfJavaScriptAction(`AFDate_FormatEx("${format}");`);
field.actions.keyPressed = new ej.pdf.PdfJavaScriptAction(`AFDate_KeystrokeEx("${format}"):`);
field.actions.validate = new ej.pdf.PdfJavaScriptAction(`AFDate_Validate("${format}");`);
// Add a new form field
form.add(field);
// Save the document
document.save('Output.pdf');
// Destroy the document
document. Destroy();

{% endhighlight %}
{% endtabs %}

## Field Auto Naming

To prevent grouping when adding fields with the same name, you can enable the `fieldAutoNaming` property of `PdfForm` class. Setting fieldAutoNaming to true ensures that each field gets a unique name internally, even if you specify the same name during creation.
Expand Down
92 changes: 92 additions & 0 deletions Document-Processing/PDF/PDF-Library/javascript/HyperLinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 36, PdfF
let size: Size = font.measureString('Syncfusion');
// Create a new text web link annotation
let annotation: PdfTextWebLinkAnnotation = new PdfTextWebLinkAnnotation({ x: 50, y: 40, width: size.width, height: size.height }, { r: 0, g: 0, b: 0}, { r: 165, g: 42, b: 42 }, 1);
// Sets the URL of the annotation.
annotation.url = ‘http://www.syncfusion.com’;
// Add annotation to the page
page.annotations.add(annotation);
// Save the document
Expand All @@ -51,6 +53,8 @@ var font = document.embedFont(ej.pdf.PdfFontFamily.helvetica, 10, ej.pdf.PdfFont
var size = font.measureString('Syncfusion');
// Create a new text web link annotation
var annotation = new ej.pdf.PdfTextWebLinkAnnotation({ x: 50, y: 40, width: size.width, height: size.height }, { r: 0, g: 0, b: 0 }, { r: 165, g: 42, b: 42 }, 1);
// Sets the URL of the annotation.
annotation.url = ‘http://www.syncfusion.com’;
// Add annotation to the page
page.annotations.add(annotation);
// Save the document
Expand Down Expand Up @@ -162,5 +166,93 @@ document.save('Output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% endtabs %}

## Modifying or updating existing hyperlinks

This example shows how to update hyperlink annotations in a PDF using Syncfusion’s JavaScript PDF Library. By accessing an annotation through `page.annotations.at()`, you can check whether it’s a link annotation and then update its URL or bounding region. This makes it easy to refresh outdated links or adjust navigation behavior whenever the document changes.

{% tabs %}
{% highlight typescript tabtitle="TypeScript" %}
import { PdfDocument, PdfPage, PdfTextWebLinkAnnotation } from '@syncfusion/ej2-pdf';

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the first page
let page: PdfPage = document.getPage(0);
// Get the first annotation of the page
let annotation: PdfTextWebLinkAnnotation = page.annotations.at(0) as PdfTextWebLinkAnnotation;
// Modified its properties
annotation.url = 'https://www.google.co.in/';
// Save the document
document.save('Output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% highlight javascript tabtitle="JavaScript" %}

// Load an existing PDF document
var document = new ej.pdf.PdfDocument(data);
// Access the first page
var page = document.getPage(0);
// Get the first annotation of the page
var annotation = page.annotations.at(0);
// Modified its properties
if (annotation instanceof ej.pdf.PdfTextWebLinkAnnotation) {
annotation.url = 'https://www.google.co.in/';
}
// Save the document
document.save('Output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% endtabs %}

## Removing hyperlinks

This example demonstrates how to remove hyperlink annotations from a PDF using Syncfusion’s JavaScript PDF Library. By reviewing each annotation and checking whether it represents a hyperlink, you can remove it using either `remove()` or `removeAt()`. This helps clean up outdated or unwanted links while keeping the rest of the document content intact.

{% tabs %}
{% highlight typescript tabtitle="TypeScript" %}
import { PdfDocument, PdfPage, PdfTextWebLinkAnnotation } from '@syncfusion/ej2-pdf';

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the first page
let page: PdfPage = document.getPage(0);
// Access first annotation from the PDF page
let annotation: PdfTextWebLinkAnnotation = page.annotations.at(0) as PdfTextWebLinkAnnotation;
// Remove an annotation from the collection
page.annotations.remove(annotation);
// Remove an annotation with specific index
page.annotations.removeAt(1);
// Save the document
document.save('output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% highlight javascript tabtitle="JavaScript" %}

// Load an existing PDF document
var document = new ej.pdf.PdfDocument(data);
// Access the first page
var page = document.getPage(0);
// Access first annotation from the PDF page
var annotation = page.annotations.at(0);
// Remove an annotation from the collection
if (annotation instanceof ej.pdf.PdfTextWebLinkAnnotation) {
page.annotations.remove(annotation);
}
// Remove an annotation with specific index
page.annotations.removeAt(1);
// Save the document
document.save('output.pdf');
// Close the document
document.destroy();

{% endhighlight %}
{% endtabs %}
Loading