ViewerDigitalSignatureValidationTest

This JavaScript sample illustrates how to view digital signature validation information in a PDF document. Learn more about our Web SDK.

1(() => {
2 const parentDocument = window.parent.document;
3 const certSelect = parentDocument.getElementById('certificate-select');
4 const certUrlForm = parentDocument.getElementById('certificate-url-form');
5 const docSelect = parentDocument.getElementById('document-select');
6 const docUrlForm = parentDocument.getElementById('document-url-form');
7 const filePicker = parentDocument.getElementById('file-picker');
8 const certUrl = parentDocument.getElementById('certificate-url');
9 const docUrl = parentDocument.getElementById('document-url');
10
11 window.addEventListener('viewerLoaded', () => {
12 const instance = window.instance;
13 const { VerificationOptions, openElements, loadDocument } = instance.UI;
14 const { documentViewer } = instance.Core;
15
16 const initialCert = 'https://pdftron.s3.amazonaws.com/downloads/pl/waiver.cer';
17 VerificationOptions.addTrustedCertificates([initialCert]);
18
19 documentViewer.addEventListener(
20 'documentLoaded',
21 () => {
22 openElements(['signaturePanel']);
23 },
24 { once: true }
25 );
26
27 certSelect.addEventListener('change', e => {
28 VerificationOptions.addTrustedCertificates([e.target.value]);
29 });
30
31 certUrlForm.addEventListener('submit', e => {
32 e.preventDefault();
33 certSelect.value = '';
34 VerificationOptions.addTrustedCertificates([certUrl.value]);
35 });
36
37 docSelect.addEventListener('change', e => {
38 loadDocument(e.target.value);
39 });
40
41 docUrlForm.addEventListener('submit', e => {
42 e.preventDefault();
43 docSelect.value = '';
44 loadDocument(docUrl.value);
45 });
46
47 filePicker.addEventListener('change', e => {
48 const file = e.target.files[0];
49
50 if (!file) {
51 return;
52 }
53
54 const ext = file.name.slice(file.name.lastIndexOf('.') + 1);
55
56 if (ext === 'cer') {
57 certSelect.value = '';
58 VerificationOptions.addTrustedCertificates([file]);
59 } else if (ext === 'pdf') {
60 docSelect.value = '';
61 loadDocument(file);
62 }
63 });
64 });
65})();
66// eslint-disable-next-line spaced-comment
67//# sourceURL=config.js

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales