Certenov0.19.0

Build a React PDF signature viewer with Certeno and Vite

In this tutorial you build a React app that opens a signed PDF, verifies every digital signature in it, and shows the result next to the document. You use Vite because it needs no bundler configuration for Certeno: it finds the WebAssembly engine and ships it beside your JavaScript on its own.

You will:

  • create a React project and install Certeno,
  • show a PDF with its signature panel and verification status,
  • add your licence, so the viewer offers the features your plan includes.

Using Next.js instead? The same component works there: see Using Next.js.


Prerequisites

  • Node.js 20.19 or later and npm.
  • A code editor.
  • Access to the Certeno registry. Certeno's packages are served from a private registry. Installation shows how to point the @trexolab scope at it.
  • A Certeno licence. You need its site ID (it starts with site_), shown on the licence. If you do not have one yet, request an evaluation or a production licence on the contact page; plans are on the pricing page. Step 4 uses 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 a React project

  1. Create a project from the Vite React and TypeScript template:

    bash
    npm create vite@latest my-app -- --template react-ts
  2. Go into it:

    bash
    cd my-app

You now have a project with src/App.tsx, src/main.tsx and src/index.css. Certeno needs React 19 or later, which the template installs.


2. Install Certeno

  1. Point the @trexolab scope at the Certeno registry, in a .npmrc file at the project root:

    bash
    echo '@trexolab:registry=https://certeno.trexolab.com/api/registry' > .npmrc
  2. Install the React package. It brings the verification engine (@trexolab/certeno-core) with it:

    bash
    npm install @trexolab/certeno-react

There is nothing else to set up. You do not add a Vite plugin, change optimizeDeps or copy a .wasm file.


3. Create the PDF viewer

  1. Make the viewer fill the window. Replace the contents of src/index.css:

    css
    html, body, #root {
      height: 100%;
      margin: 0;
      padding: 0;
    }
  2. Replace the contents of src/App.tsx:

    tsx
    import { useState } from 'react'
    import {
      CertenoProvider,
      Viewer,
      WelcomeScreen,
      useVerification,
      defaultLayoutPlugin,
    } from '@trexolab/certeno-react'
    import '@trexolab/certeno-react/styles.css'
     
    function PdfViewer() {
      const verification = useVerification()
      const [layout] = useState(() => defaultLayoutPlugin())
     
      if (!verification.fileBuffer) {
        return <WelcomeScreen onOpenFile={(file) => verification.load(file)} />
      }
     
      return (
        <Viewer
          fileBuffer={verification.fileBuffer}
          fileName={verification.fileName}
          plugins={[layout.plugin]}
          onOpenFile={(file) => verification.load(file)}
          signatures={verification.signatures}
          unsignedFields={verification.unsignedFields}
          verificationStatus={verification.status ?? undefined}
        />
      )
    }
     
    export default function App() {
      return (
        <CertenoProvider
          config={{
            workerUrl: 'https://unpkg.com/[email protected]/legacy/build/pdf.worker.min.mjs',
            theme: { mode: 'system' },
          }}
        >
          <PdfViewer />
        </CertenoProvider>
      )
    }

Here is what the code does:

  • CertenoProvider loads the engine and sets up theming.
  • useVerification() holds the open file and its verification result, and gives you load() to open another.
  • WelcomeScreen is the drag-and-drop page you see until a file is opened.
  • Viewer shows the PDF with the default layout (toolbar, sidebar, page navigation, signature panel).

Note: workerUrl is required. It points at the PDF.js worker, which must be the same version as the PDF.js that Certeno ships with (5.5.207). The address above loads it from a CDN. To serve it yourself, or to see why the versions must match, read PDF.js Worker Setup.


4. 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 says so.

  1. Add the licence hooks to the imports in src/App.tsx:

    tsx
    import {
      CertenoProvider,
      Viewer,
      WelcomeScreen,
      useVerification,
      defaultLayoutPlugin,
      useLicence,
      licenceNoticePlugin,
      LicenceFeaturesProvider,
      type LicenceState,
    } from '@trexolab/certeno-react'
  2. Change PdfViewer to take the licence, and App to check it. Replace site_… with your site ID:

    tsx
    function PdfViewer({ licence }: { licence: LicenceState }) {
      const verification = useVerification()
      const [layout] = useState(() => defaultLayoutPlugin())
     
      if (!verification.fileBuffer) {
        return <WelcomeScreen onOpenFile={(file) => verification.load(file)} />
      }
     
      // A licence that did not verify keeps the free features, and says so.
      const plugins =
        !licence.licensed && licence.reason !== 'NO_LICENCE'
          ? [layout.plugin, licenceNoticePlugin()]
          : [layout.plugin]
     
      return (
        <Viewer
          fileBuffer={verification.fileBuffer}
          fileName={verification.fileName}
          plugins={plugins}
          onOpenFile={(file) => verification.load(file)}
          signatures={verification.signatures}
          unsignedFields={verification.unsignedFields}
          verificationStatus={verification.status ?? undefined}
        />
      )
    }
     
    const config = {
      workerUrl: 'https://unpkg.com/[email protected]/legacy/build/pdf.worker.min.mjs',
      theme: { mode: 'system' as const },
    }
     
    export default function App() {
      const licence = useLicence({ siteId: 'site_…' })
     
      // The check takes a moment, at most five seconds. Render once it is done,
      // so a control never appears and then disappears.
      if (!licence.ready) return null
     
      // LicenceFeaturesProvider goes above CertenoProvider.
      return (
        <LicenceFeaturesProvider features={licence.features}>
          <CertenoProvider config={config}>
            <PdfViewer licence={licence} />
          </CertenoProvider>
        </LicenceFeaturesProvider>
      )
    }

The site ID is public, like a publishable key, so it is safe in page code. Keep your licence key and API keys out of it. The viewer asks the licence server for a short-lived token for the page's origin, keeps it in the browser, and renews it on its own. Nothing about the PDF is sent.

Note: The licence is tied to the domains on it. Make sure the domain your app runs on is on the licence, including the one you develop on and your production domain. For the other ways to configure it (a signed domain token, no network request), see Licensing.


5. Verify your output

  1. Start the dev server:

    bash
    npm run dev
  2. Open the address it prints. You should see the Open a PDF screen: "Drag and drop a file here, or click to browse".

  3. Drop in your signed PDF. You should see:

    • the document, with page navigation and zoom in the toolbar;
    • a Signatures panel that counts the signatures and lists each one with its signer, revision, signing time and a status line;
    • a banner above the document, "At least one signature has problems.", when any signature is not fully valid, with a button that opens the panel;
    • any unsigned signature fields, marked Not signed.

    Each signature gets one overall status: valid, warning, invalid or unknown. A signature shows as unknown when its certificate does not chain to a root Certeno trusts, which is expected for a test certificate you made yourself. To trust your own roots, see Custom Trust Store.

  4. To see what an unverified licence looks like, 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 banner reading "Some features are unavailable because the licence could not be verified." The browser console shows the request to the licence server failing. Put your real site ID back.

If something is not as described, see Troubleshooting.


Using Next.js

The viewer is a client component. Put the code from steps 3 and 4 in a file that starts with 'use client', and import it from a page like any other component. You do not need next/dynamic or ssr: false. Examples shows the wrapper and a page that uses it.


Next steps

  • Licensing: the other ways to configure a licence, what each feature unlocks, and what the viewer does when the check fails.
  • React Integration: the full set of components, hooks and plugins.
  • Customization: themes, CSS variables and the toolbar.
  • Revocation Checking: check whether a certificate has been revoked.
  • Examples: recipes for custom trust stores, metadata and certificate export.
  • Deployment: the production checklist, including the Content Security Policy.