VerifyKitv0.5.1

Vanilla API Reference

@trexolab/verifykit-vanilla

Zero-build CDN/UMD drop-in PDF viewer with signature verification. No React knowledge required. Bundles React 19 internally and exposes all viewer features as imperative JavaScript methods.


create(container, options?)

Creates a viewer instance mounted on the given DOM element. The WASM verification engine is initialized automatically on first use.

ts
function create(container: HTMLElement, options?: VerifyKitOptions): VerifyKitInstance

Also available as VerifyKit.create() (UMD global).

Parameters:

ParameterTypeRequiredDescription
containerHTMLElementYesThe DOM element to mount the viewer in
optionsVerifyKitOptionsNoConfiguration options

Throws: If container is not a valid HTMLElement.

Example (CDN):

html
<script src="https://verifykit.trexolab.com/cdn/verifykit.umd.js"></script>
<script>
  const viewer = VerifyKit.create(document.getElementById('viewer'), {
    workerUrl: 'https://unpkg.com/pdfjs-dist@5.5.207/legacy/build/pdf.worker.min.mjs',
    theme: { mode: 'system' },
    features: { signatures: true, download: true },
  })
 
  viewer.load('/document.pdf')
</script>

Example (ESM):

ts
import { create } from '@trexolab/verifykit-vanilla'
import '@trexolab/verifykit-vanilla/verifykit.css'
 
const viewer = create(document.getElementById('viewer'), {
  workerUrl: 'https://unpkg.com/pdfjs-dist@5.5.207/legacy/build/pdf.worker.min.mjs',
  theme: { mode: 'system' },
})
 
const result = await viewer.load(pdfArrayBuffer, 'report.pdf')
console.log('Signatures:', result.signatures.length)

VerifyKitOptions

ts
interface VerifyKitOptions {
  workerUrl: string             // REQUIRED. URL to the PDF.js worker script.
  theme?: { mode?: 'light' | 'dark' | 'system'; overrides?: Record<string, string> }
  features?: VerifyKitFeatures
  trustStore?: TrustStoreConfig
  plugins?: VerifyKitPlugin[]
  locale?: string
  translations?: Partial<TranslationStrings>
  onVerified?: (result: VerificationResult) => void
  onError?: (error: LoadError) => void
  onDocumentLoaded?: (info: { pageCount: number; fileName: string }) => void
  onPageChange?: (page: number) => void
  onZoomChange?: (scale: number) => void
  onThemeChange?: (mode: 'light' | 'dark') => void
}
PropertyTypeDescription
workerUrlstringRequired. URL to the PDF.js worker script. Use 'https://unpkg.com/pdfjs-dist@5.5.207/legacy/build/pdf.worker.min.mjs' or self-host.
themeobjectTheme configuration with mode and optional CSS variable overrides
featuresVerifyKitFeaturesGranular feature flags (see below)
trustStoreTrustStoreConfigCustom root CA certificates for verification
pluginsVerifyKitPlugin[]Core plugins (e.g., revocationPlugin())
localestringLocale code (default: 'en')
translationsPartial<TranslationStrings>Custom translation overrides
onVerified(result) => voidCallback when verification completes
onError(error: LoadError) => voidCallback on error (see LoadError type below)
onDocumentLoaded(info) => voidCallback when document is loaded
onPageChange(page) => voidCallback when page changes
onZoomChange(scale) => voidCallback when zoom changes
onThemeChange(mode) => voidCallback when theme changes

Feature Flags

ts
interface VerifyKitFeatures {
  search?: boolean       // default: true
  print?: boolean        // default: true
  download?: boolean     // default: false
  signatures?: boolean   // default: true
  thumbnails?: boolean   // default: true
  fullscreen?: boolean   // default: true
  themeToggle?: boolean  // default: true
  openFile?: boolean     // default: false
  rotation?: boolean     // default: true
  contextMenu?: boolean  // default: true
  properties?: boolean   // default: true
  shortcuts?: boolean    // default: true
  highlights?: boolean   // default: true
  accessibility?: boolean  // default: true
}
FlagDefaultDescription
searchtrueEnable text search (Ctrl+F)
printtrueEnable print (Ctrl+P)
downloadfalseEnable download (Ctrl+S)
signaturestrueEnable signature verification panel
thumbnailstrueEnable thumbnail sidebar tab
fullscreentrueEnable fullscreen mode (F5)
themeToggletrueEnable light/dark theme toggle
openFilefalseEnable open file button and drag-drop
rotationtrueEnable document rotation
contextMenutrueEnable right-click context menu
propertiestrueEnable document properties
shortcutstrueEnable keyboard shortcuts help (?)
highlightstrueEnable text highlighting
accessibilitytrueEnable UI font scale control (Aa button)

VerifyKitInstance Methods

The object returned by create().

Document

load(input, fileName?)

Load and verify a PDF document.

ts
load(input: PdfInput, fileName?: string): Promise<VerificationResult>
ParameterTypeRequiredDescription
inputPdfInputYesFile, ArrayBuffer, Uint8Array, or URL string
fileNamestringNoDisplay name for the file

Returns: Promise<VerificationResult> with all signature data.

ts
const result = await viewer.load(buffer, 'contract.pdf')
console.log(result.signatures[0].overallStatus) // "valid"

destroy()

Destroy the viewer and clean up all resources (React root, store subscriptions, event listeners, worker blob URLs).

ts
destroy(): void

Theme

setTheme(mode)

Change the viewer theme.

ts
setTheme(mode: 'light' | 'dark' | 'system'): void

goToPage(page)

Navigate to a specific page (1-based).

ts
goToPage(page: number): void

goToPreviousPage()

Navigate to the previous page.

ts
goToPreviousPage(): void

goToNextPage()

Navigate to the next page.

ts
goToNextPage(): void

goToFirstPage()

Navigate to the first page.

ts
goToFirstPage(): void

goToLastPage()

Navigate to the last page.

ts
goToLastPage(): void

getCurrentPage()

Get the current page number (1-based).

ts
getCurrentPage(): number

getPageCount()

Get the total page count.

ts
getPageCount(): number

Zoom

zoomIn()

Increase the zoom level.

ts
zoomIn(): void

zoomOut()

Decrease the zoom level.

ts
zoomOut(): void

zoomTo(scale)

Set zoom to a specific scale value (e.g., 1.0 = 100%, 2.0 = 200%).

ts
zoomTo(scale: number): void

setFitMode(mode)

Set the document fit mode.

ts
setFitMode(mode: 'none' | 'width' | 'page'): void
ModeDescription
'none'No automatic fitting
'width'Fit to container width
'page'Fit entire page in view

getZoom()

Get the current zoom scale value.

ts
getZoom(): number

Rotation

rotateCW()

Rotate the document clockwise by 90 degrees.

ts
rotateCW(): void

rotateCCW()

Rotate the document counter-clockwise by 90 degrees.

ts
rotateCCW(): void

getRotation()

Get the current rotation in degrees (0, 90, 180, or 270).

ts
getRotation(): number

openSearch()

Open the search bar.

ts
openSearch(): void

closeSearch()

Close the search bar.

ts
closeSearch(): void

print()

Print the document using the browser's print dialog.

ts
print(): void

download()

Download the document. Requires the download feature to be enabled.

ts
download(): void

Fullscreen

enterFullscreen()

Enter fullscreen mode.

ts
enterFullscreen(): void

exitFullscreen()

Exit fullscreen mode.

ts
exitFullscreen(): void

toggleFullscreen()

Toggle fullscreen mode.

ts
toggleFullscreen(): void

Signature Panel

openSignaturePanel()

Open the signature details panel.

ts
openSignaturePanel(): void

closeSignaturePanel()

Close the signature details panel.

ts
closeSignaturePanel(): void

Accessibility

setFontScale(scale)

Set the UI font scale for the viewer. Affects all text, toolbar buttons, and panel heights.

ts
setFontScale(scale: 'compact' | 'default' | 'large' | 'extra-large'): void
ScaleMultiplierDescription
compact0.88xSmaller UI for information density
default1.00xStandard size
large1.15xLarger text for readability
extra-large1.30xMaximum readability

getFontScale()

Get the current UI font scale.

ts
getFontScale(): 'compact' | 'default' | 'large' | 'extra-large'

Revalidation

revalidate()

Re-verify all signatures on the current in-memory buffer. Useful after installing a revocation plugin or when you want to refresh revocation status without reloading the PDF.

ts
revalidate(): Promise<VerificationResult | null>

Returns: Promise<VerificationResult | null> — the updated verification result, or null if no document is loaded.

ts
const updated = await viewer.revalidate()
if (updated) {
  console.log('Re-verified:', updated.signatures.length, 'signatures')
}

Events

on(event, handler)

Subscribe to viewer events. Returns an unsubscribe function.

ts
on(event: string, handler: (...args: unknown[]) => void): () => void

Supported events:

EventPayloadDescription
pageChangenumberCurrent page changed
zoomChangenumberZoom scale changed
themeChange'light' | 'dark'Theme mode changed
rotationChangenumberRotation changed
fullscreenChangebooleanFullscreen state changed
fontScaleChangestringUI font scale changed
documentLoaded{ pageCount: number; fileName: string }Document finished loading
verifiedVerificationResultVerification completed
errorLoadErrorError occurred (object with name and message)

Example:

ts
const unsub = viewer.on('pageChange', (page) => {
  console.log('Current page:', page)
})
 
viewer.on('verified', (result) => {
  console.log('Signatures:', result.signatures.length)
})
 
// Unsubscribe
unsub()

State

getVerificationResult()

Get the last verification result, or null if no document has been verified.

ts
getVerificationResult(): VerificationResult | null

getSignatures()

Get the current signature list. Returns an empty array if no document is loaded.

ts
getSignatures(): PdfSignature[]

Callbacks

Callbacks can be provided in VerifyKitOptions as an alternative to the event system:

CallbackSignatureDescription
onVerified(result: VerificationResult) => voidCalled when signature verification completes
onError(error: LoadError) => voidCalled when an error occurs
onDocumentLoaded(info: { pageCount: number; fileName: string }) => voidCalled when the PDF is loaded in the viewer
onPageChange(page: number) => voidCalled when the current page changes
onZoomChange(scale: number) => voidCalled when the zoom level changes
onThemeChange(mode: 'light' | 'dark') => voidCalled when the theme mode changes

Example:

ts
const viewer = VerifyKit.create(el, {
  workerUrl: 'https://unpkg.com/pdfjs-dist@5.5.207/legacy/build/pdf.worker.min.mjs',
  onVerified: (result) => {
    for (const sig of result.signatures) {
      console.log(`${sig.name}: ${sig.overallStatus}`)
    }
  },
  onError: (error) => console.error('Verification error:', error),
  onPageChange: (page) => updatePageIndicator(page),
})

LoadError

Error object passed to the onError callback and the error event.

ts
interface LoadError {
  name: LoadErrorName
  message: string
}
 
type LoadErrorName =
  | 'InvalidPDFException'
  | 'MissingPDFException'
  | 'UnexpectedResponseException'
  | 'PasswordException'
  | 'AbortException'
  | 'FormatError'
  | 'NetworkError'
  | 'UnsupportedInputError'
  | 'VerificationError'
  | 'UnknownErrorException'

Example:

ts
const viewer = VerifyKit.create(el, {
  workerUrl: 'https://unpkg.com/pdfjs-dist@5.5.207/legacy/build/pdf.worker.min.mjs',
  onError: (error) => {
    console.error(`[${error.name}] ${error.message}`)
    // error.name is one of the LoadErrorName values
  },
})

Complete Example

ts
const viewer = VerifyKit.create(document.getElementById('viewer'), {
  workerUrl: 'https://unpkg.com/pdfjs-dist@5.5.207/legacy/build/pdf.worker.min.mjs',
  theme: { mode: 'system' },
  features: { download: true, openFile: true },
})
 
// Load a document
await viewer.load(buffer, 'doc.pdf')
 
// Navigate
viewer.goToPage(5)
viewer.goToNextPage()
console.log('Page:', viewer.getCurrentPage(), '/', viewer.getPageCount())
 
// Zoom
viewer.zoomIn()
viewer.zoomTo(2.0)
viewer.setFitMode('width')
console.log('Zoom:', viewer.getZoom())
 
// Rotate
viewer.rotateCW()
console.log('Rotation:', viewer.getRotation())
 
// Search, print, download
viewer.openSearch()
viewer.print()
viewer.download()
 
// Fullscreen
viewer.toggleFullscreen()
 
// Signatures
viewer.openSignaturePanel()
console.log('Signatures:', viewer.getSignatures())
console.log('Result:', viewer.getVerificationResult())
 
// Re-verify signatures
const updated = await viewer.revalidate()
 
// Clean up
viewer.destroy()