Add a PDF signature viewer to any web page with Certeno
In this tutorial you build one HTML page that opens a signed PDF, verifies every digital signature in it, and shows the result in a viewer. There is no build step, no bundler and no framework: you load Certeno with two tags, from a CDN.
You will:
- create a page with a viewer on it,
- open a PDF from your computer and read the verification result,
- add your licence, so the viewer offers the features your plan includes.
Using a bundler instead? Vanilla JS shows the npm install. Using Vue? See Vue Integration.
Prerequisites
- A web browser and a code editor.
- Node.js and npm, only to start a local web server in step 2. Any static file server works instead.
- A Certeno licence, for step 3. You need its site ID (it starts with
site_). If you do not have one yet, request an evaluation or a production licence on the contact page. Steps 1 and 2 work without it. - A PDF with a digital signature, to see something to verify.
Tip: You can try the verification itself, with no licence, in the live demo before you set anything up.
1. Create the page
-
Create a folder and a file named
index.htmlin it, with this content:html<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>PDF signature viewer</title> <style> html, body { height: 100%; margin: 0; } body { display: flex; flex-direction: column; font-family: system-ui, sans-serif; } header { padding: 12px 16px; border-bottom: 1px solid #ddd; display: flex; gap: 16px; align-items: center; } #summary { margin: 0; color: #444; } #viewer { flex: 1; min-height: 0; } </style> </head> <body> <header> <input id="file" type="file" accept="application/pdf" /> <p id="summary">Choose a signed PDF.</p> </header> <div id="viewer"></div> </body> </html>
The viewer fills the element you give it, so that element needs a height. Here the body is a column that fills the window and #viewer takes the space left under the header. A container with no height shows nothing.
2. Add Certeno
-
Add the stylesheet inside
<head>, after the<style>block:html<link rel="stylesheet" href="https://certeno.trexolab.com/cdn/certeno.css" /> -
Add the script and the code that starts the viewer, just before
</body>:html<script src="https://certeno.trexolab.com/cdn/certeno.umd.js"></script> <script> const viewer = Certeno.create(document.getElementById('viewer'), { // pdf.js renders the pages. Its worker file must be reachable from the page. workerUrl: 'https://unpkg.com/[email protected]/legacy/build/pdf.worker.min.mjs', theme: { mode: 'system' }, }) </script>The script defines
Certenoas a global.Certeno.create(container, options)mounts the viewer in the container and returns it. -
Serve the folder. Opening the file by double-clicking does not work, because the browser blocks scripts from a
file://address. From the folder, run:bashnpx serve .and open the address it prints.
The verification engine is a WebAssembly file that the script loads from the same place on the CDN, so there is nothing else to download or copy.
3. Add your licence
Certeno is a licensed SDK. Until you add a licence the viewer offers only the free features: it shows the PDF and verifies nothing. With one, it checks the licence and offers the features it includes. A licence that cannot be verified never stops a PDF from opening: the viewer falls back to the free features and shows a short notice.
-
Add the
licensingoption and anonLicencecallback to the options ofCerteno.create, replacingsite_…with the site ID from your licence:jsconst viewer = Certeno.create(document.getElementById('viewer'), { workerUrl: 'https://unpkg.com/[email protected]/legacy/build/pdf.worker.min.mjs', theme: { mode: 'system' }, licensing: { siteId: 'site_…' }, onLicence: ({ licensed, reason }) => { if (!licensed) console.warn('Licence not verified:', reason) }, }) -
Reload the page. The viewer is held back for a moment while the licence is checked, then it opens with the features your plan includes.
A site ID is public. It identifies your licence and is checked against the domains the licence is registered for, so it is safe to put in a page. The domains are listed on the licence.
4. Open a PDF and read the result
-
Add this inside the second
<script>, after theCerteno.create(...)call:jsconst summary = document.getElementById('summary') document.getElementById('file').addEventListener('change', async (event) => { const file = event.target.files[0] if (!file) return summary.textContent = 'Verifying…' const result = await viewer.load(await file.arrayBuffer(), file.name) if (result.verificationSkipped) { summary.textContent = `${file.name} was opened. Your licence does not include verification.` return } const signatures = result.signatures summary.textContent = signatures.length === 0 ? `${file.name} has no signatures.` : `${signatures.length} signature(s): ` + signatures.map((s) => `${s.name} is ${s.overallStatus}`).join(', ') }) -
Reload the page, choose your signed PDF, and read the line in the header.
viewer.load(source, fileName) opens the document, verifies it, and resolves to the full result. The viewer shows the same result in its signature panel. Each signature gets one overall status: valid, warning, invalid or unknown. A signature that is intact but whose certificate does not chain to a root Certeno trusts shows as warning. That is expected for a test certificate.
Note: Every other method on the viewer (such as goToPage or zoomIn) does nothing until load() has resolved, so await it first.
5. Verify your output
-
Open your PDF again. You should see:
- the document, with page navigation and zoom in the toolbar;
- a Signatures panel that lists each signature with its signer and a status line;
- the same summary in the page header.
-
Open the browser's developer console. With a verified licence there is no warning.
-
To see an unverified licence, change the site ID to a made-up value and reload. The PDF still opens, but with only the free features: no verification, no signature panel, and a notice that some features are unavailable. The console shows
Licence not verified:and the reason (NO_TOKENhere), and a failed request to the licence server.
If something is not as described, see Troubleshooting.
Next steps
- Vanilla JS: every option, method and event, and how to host the files yourself.
- Licensing: what each feature unlocks, and what the viewer does when the check fails.
- Customization: themes and CSS variables.
- Revocation Checking: check whether a certificate has been revoked.
- Deployment: the production checklist, including the Content Security Policy.