> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/get-started/samples/viewerdigitalsignaturevalidationtest.md).

# Validate Digital Signature - Sample Code

View digital signature validation information in PDFs using JavaScript. Makes it easy to see the whether a signature is valid when viewing a PDF.

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/web/get-started/readme.md" class="button primary">Web SDK</a><a href="https://apryse.com/capabilities#DigitalSignature" class="button primary">Package: Digital Signature</a><a href="/web/full-api/full-api-overview.md" class="button primary">Full API</a><a href="https://showcase.apryse.com/digital-signatures" class="button primary">Live demo</a>
{% endhint %}

This JavaScript sample illustrates how to view digital signature validation information in a PDF document.

### **Implementation steps**

To validate a digital signature with WebViewer:

Step 1: Follow [get started in your preferred web stack for WebViewer](/web/get-started/readme.md) Step 2: [Enable the full API ](/web/full-api/full-api-overview.md)by passing the `fullAPI` option into the WebViewer constructor Step 3: Add the sample code provided in this guide

This full sample is included in the [manual download of WebViewer.](/web/get-started/manually.md#1-download-webviewer)

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
(() => {
  const parentDocument = window.parent.document;
  const certSelect = parentDocument.getElementById('certificate-select');
  const certUrlForm = parentDocument.getElementById('certificate-url-form');
  const docSelect = parentDocument.getElementById('document-select');
  const docUrlForm = parentDocument.getElementById('document-url-form');
  const filePicker = parentDocument.getElementById('file-picker');
  const certUrl = parentDocument.getElementById('certificate-url');
  const docUrl = parentDocument.getElementById('document-url');

  window.addEventListener('viewerLoaded', () => {
    const instance = window.instance;
    const { VerificationOptions, openElements, loadDocument } = instance.UI;
    const { documentViewer } = instance.Core;

    const initialCert = 'https://pdftron.s3.amazonaws.com/downloads/pl/waiver.cer';
    VerificationOptions.addTrustedCertificates([initialCert]);

    documentViewer.addEventListener(
      'documentLoaded',
      () => {
        openElements(['signaturePanel']);
      },
      { once: true }
    );

    certSelect.addEventListener('change', e => {
      VerificationOptions.addTrustedCertificates([e.target.value]);
    });

    certUrlForm.addEventListener('submit', e => {
      e.preventDefault();
      certSelect.value = '';
      VerificationOptions.addTrustedCertificates([certUrl.value]);
    });

    docSelect.addEventListener('change', e => {
      loadDocument(e.target.value);
    });

    docUrlForm.addEventListener('submit', e => {
      e.preventDefault();
      docSelect.value = '';
      loadDocument(docUrl.value);
    });

    filePicker.addEventListener('change', e => {
      const file = e.target.files[0];

      if (!file) {
        return;
      }

      const ext = file.name.slice(file.name.lastIndexOf('.') + 1);

      if (ext === 'cer') {
        certSelect.value = '';
        VerificationOptions.addTrustedCertificates([file]);
      } else if (ext === 'pdf') {
        docSelect.value = '';
        loadDocument(file);
      }
    });
  });
})();
// eslint-disable-next-line spaced-comment
//# sourceURL=config.js
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/get-started/samples/viewerdigitalsignaturevalidationtest.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
