Skip to content

Commit 3c1d611

Browse files
1010299: upto changes commit
1 parent 1aebfbf commit 3c1d611

4 files changed

Lines changed: 484 additions & 0 deletions

File tree

Document-Processing/PDF/PDF-Library/javascript/DigitalSignature.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,5 +884,135 @@ var signedDocumentData = ej.pdf.PdfSignature.replaceEmptySignature(
884884
// Destroy the document
885885
document.destroy();
886886

887+
{% endhighlight %}
888+
{% endtabs %}
889+
890+
## Document revisions
891+
892+
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.
893+
894+
{% tabs %}
895+
{% highlight typescript tabtitle="TypeScript" %}
896+
import {PdfDocument, PdfForm, PdfSignatureField} from '@syncfusion/ej2-pdf';
897+
898+
// Load an existing PDF document
899+
let document: PdfDocument = new PdfDocument(data);
900+
// Access loaded form
901+
let form: PdfForm = document.form;
902+
// Access the loaded form field
903+
let signature: PdfSignatureField = form.fieldAt(0);
904+
// Retrieve all revision indexes of the PDF document
905+
let revisions: number[] = document.getRevisions();
906+
// Gets the revision number associated with the signature field
907+
let revision: number = signature.getRevision();
908+
// Destroy the document
909+
document.destroy();
910+
911+
{% endhighlight %}
912+
{% highlight javascript tabtitle="JavaScript" %}
913+
914+
// Load an existing PDF document
915+
var document = new ej.pdf.PdfDocument(data);
916+
// Access loaded form
917+
var form = document.form;
918+
// Access the loaded form field
919+
var signature = form.fieldAt(0);
920+
// Retrieve all revision indexes of the PDF document
921+
var revisions = document.getRevisions();
922+
// Gets the revision number associated with the signature field
923+
var revision = signature.getRevision();
924+
// Destroy the document
925+
document.destroy();
926+
927+
{% endhighlight %}
928+
{% endtabs %}
929+
930+
## Sign existing signature field
931+
932+
This section explains how to apply a digital signature to an existing unsigned signature field in a PDF form. The JavaScript PDF library lets you locate predefined signature fields and sign them without modifying the document layout. This is especially useful for templates where signature placeholders already exist. By applying a certificate and signature settings, you can securely complete the signature field and follow standard PDF signing workflows.
933+
934+
{% tabs %}
935+
{% highlight typescript tabtitle="TypeScript" %}
936+
import {PdfDocument, PdfForm, DigestAlgorithm, CryptographicStandard, PdfSignatureField} from '@syncfusion/ej2-pdf';
937+
938+
// Load an existing PDF document
939+
let document: PdfDocument = new PdfDocument(data);
940+
// Access loaded form
941+
let form: PdfForm = document.form;
942+
// Access the loaded form field
943+
let field: PdfSignatureField = form.fieldAt(0);
944+
// Create a digital signature with CMS + SHA-256
945+
const signature: PdfSignature = PdfSignature.create(certificate, 'password', {
946+
digestAlgorithm: DigestAlgorithm.sha256,
947+
cryptographicStandard: CryptographicStandard.cms
948+
});
949+
// Apply the signature to the field
950+
field.setSignature(signature);
951+
// Add a form field
952+
document.form.add(field);
953+
// Destroy the document
954+
document.destroy();
955+
956+
{% endhighlight %}
957+
{% highlight javascript tabtitle="JavaScript" %}
958+
959+
// Load an existing PDF document
960+
var document = new ej.pdf.PdfDocument(data);
961+
// Access loaded form
962+
var form = document.form;
963+
// Access the loaded form field
964+
var field = form.fieldAt(0);
965+
// Create a digital signature with CMS + SHA-256
966+
const signature = ej.pdf.PdfSignature.create(certificate, 'password', {
967+
digestAlgorithm: ej.pdf.DigestAlgorithm.sha256,
968+
cryptographicStandard: ej.pdf.CryptographicStandard.cms
969+
});
970+
// Apply the signature to the field
971+
field.setSignature(signature);
972+
// Add a form field
973+
document.form.add(field);
974+
// Destroy the document
975+
document.destroy();
976+
977+
{% endhighlight %}
978+
{% endtabs %}
979+
980+
## Remove existing digital signature
981+
982+
This section explains how to remove one or more digital signatures from a PDF and restore the document to an signed or unsigned state. The JavaScript PDF library allows you to clear signature dictionaries so the file can be edited, re‑signed, or corrected. Removing a signature also invalidates any associated certification, making the document fully editable again. This is useful when preparing a PDF for updates or resolving signature‑related issues.
983+
984+
{% tabs %}
985+
{% highlight typescript tabtitle="TypeScript" %}
986+
import {PdfDocument, PdfForm, PdfSignatureField} from '@syncfusion/ej2-pdf';
987+
988+
// Load an existing PDF document
989+
let document: PdfDocument = new PdfDocument(data);
990+
// Access loaded form
991+
let form: PdfForm = document.form;
992+
// Access the loaded form field
993+
let field: PdfSignatureField = form.fieldAt(0) as PdfSignatureField;
994+
// Remove the form field
995+
if (field instanceof PdfSignatureField ) {
996+
document.form.removeField(field);
997+
}
998+
// Destroy the document
999+
document.destroy();
1000+
1001+
{% endhighlight %}
1002+
{% highlight javascript tabtitle="JavaScript" %}
1003+
1004+
// Load an existing PDF document
1005+
var document = new ej.pdf.PdfDocument(data);
1006+
// Access loaded form
1007+
var form = document.form;
1008+
// Access the loaded form field
1009+
var field = form.fieldAt(0);
1010+
// Remove the form field
1011+
if (field instanceof ej.pdf.PdfSignatureField ) {
1012+
document.form.removeField(field);
1013+
}
1014+
// Destroy the document
1015+
document.destroy();
1016+
8871017
{% endhighlight %}
8881018
{% endtabs %}

Document-Processing/PDF/PDF-Library/javascript/FormFields.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,70 @@ document. Destroy();
851851
{% endhighlight %}
852852
{% endtabs %}
853853

854+
## Add a date field to a PDF form
855+
856+
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 also use `dateField.actions` to trigger custom scripts or validations when the field is focused, changed, or submitted.
857+
858+
{% tabs %}
859+
{% highlight typescript tabtitle="TypeScript" %}
860+
import {PdfDocument, pdfPage, PdfForm, PdfTextBoxField, PdfJavaScriptAction, PdfFormFieldsTabOrder } from '@syncfusion/ej2-pdf';
861+
862+
// Create a new PDF document
863+
let document: PdfDocument = new PdfDocument();
864+
// Add a new page to the document
865+
let page: pdfPage = document.addPage();
866+
// Access loaded form
867+
let form: PdfForm = document.form;
868+
// Create a new text box field
869+
const field: PdfTextBoxField = new PdfTextBoxField(page, 'fieldF', {
870+
x: 50, y: 200, width: 150, height: 20,
871+
});
872+
// Sets the text value to text box field
873+
field.text = '18/08/2003';
874+
// Sets date formate
875+
const format: string = 'yyyy-mm-dd';
876+
// Create a new `PdfJavaScriptAction` for adding the action
877+
field.actions.format = new PdfJavaScriptAction(`AFDate_FormatEx("${format}");`);
878+
field.actions.keyPressed = new PdfJavaScriptAction(`AFDate_KeystrokeEx("${format}"):`);
879+
field.actions.validate = new PdfJavaScriptAction(`AFDate_Validate("${format}");`);
880+
// Add a new form field
881+
form.add(field);
882+
// Save the document
883+
document.save('output.pdf');
884+
// Destroy the document
885+
document. Destroy();
886+
887+
{% endhighlight %}
888+
{% highlight javascript tabtitle="JavaScript" %}
889+
890+
// Create a new PDF document instance
891+
var document = new ej.pdf.PdfDocument();
892+
// Add a new page to the document
893+
var page = document.addPage();
894+
// Access loaded form
895+
var form = document.form;
896+
// Create a new text box field
897+
const field = new ej.pdf.PdfTextBoxField(page, 'fieldF', {
898+
x: 50, y: 200, width: 150, height: 20,
899+
});
900+
// Sets the text value to text box field
901+
field.text = '18/08/2003';
902+
// Sets date formate
903+
const format = 'yyyy-mm-dd';
904+
// Create a new `PdfJavaScriptAction` for adding the action
905+
field.actions.format = new ej.pdf.PdfJavaScriptAction(`AFDate_FormatEx("${format}");`);
906+
field.actions.keyPressed = new ej.pdf.PdfJavaScriptAction(`AFDate_KeystrokeEx("${format}"):`);
907+
field.actions.validate = new ej.pdf.PdfJavaScriptAction(`AFDate_Validate("${format}");`);
908+
// Add a new form field
909+
form.add(field);
910+
// Save the document
911+
document.save('Output.pdf');
912+
// Destroy the document
913+
document. Destroy();
914+
915+
{% endhighlight %}
916+
{% endtabs %}
917+
854918
## Field Auto Naming
855919

856920
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.

0 commit comments

Comments
 (0)