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.
function create(container: HTMLElement, options?: VerifyKitOptions): VerifyKitInstanceAlso available as VerifyKit.create() (UMD global).
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
container | HTMLElement | Yes | The DOM element to mount the viewer in |
options | VerifyKitOptions | No | Configuration options |
Throws: If container is not a valid HTMLElement.
Example (CDN):
<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):
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
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
}| Property | Type | Description |
|---|---|---|
workerUrl | string | Required. 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. |
theme | object | Theme configuration with mode and optional CSS variable overrides |
features | VerifyKitFeatures | Granular feature flags (see below) |
trustStore | TrustStoreConfig | Custom root CA certificates for verification |
plugins | VerifyKitPlugin[] | Core plugins (e.g., revocationPlugin()) |
locale | string | Locale code (default: 'en') |
translations | Partial<TranslationStrings> | Custom translation overrides |
onVerified | (result) => void | Callback when verification completes |
onError | (error: LoadError) => void | Callback on error (see LoadError type below) |
onDocumentLoaded | (info) => void | Callback when document is loaded |
onPageChange | (page) => void | Callback when page changes |
onZoomChange | (scale) => void | Callback when zoom changes |
onThemeChange | (mode) => void | Callback when theme changes |
Feature Flags
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
}| Flag | Default | Description |
|---|---|---|
search | true | Enable text search (Ctrl+F) |
print | true | Enable print (Ctrl+P) |
download | false | Enable download (Ctrl+S) |
signatures | true | Enable signature verification panel |
thumbnails | true | Enable thumbnail sidebar tab |
fullscreen | true | Enable fullscreen mode (F5) |
themeToggle | true | Enable light/dark theme toggle |
openFile | false | Enable open file button and drag-drop |
rotation | true | Enable document rotation |
contextMenu | true | Enable right-click context menu |
properties | true | Enable document properties |
shortcuts | true | Enable keyboard shortcuts help (?) |
highlights | true | Enable text highlighting |
accessibility | true | Enable UI font scale control (Aa button) |
VerifyKitInstance Methods
The object returned by create().
Document
load(input, fileName?)
Load and verify a PDF document.
load(input: PdfInput, fileName?: string): Promise<VerificationResult>| Parameter | Type | Required | Description |
|---|---|---|---|
input | PdfInput | Yes | File, ArrayBuffer, Uint8Array, or URL string |
fileName | string | No | Display name for the file |
Returns: Promise<VerificationResult> with all signature data.
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).
destroy(): voidTheme
setTheme(mode)
Change the viewer theme.
setTheme(mode: 'light' | 'dark' | 'system'): voidNavigation
goToPage(page)
Navigate to a specific page (1-based).
goToPage(page: number): voidgoToPreviousPage()
Navigate to the previous page.
goToPreviousPage(): voidgoToNextPage()
Navigate to the next page.
goToNextPage(): voidgoToFirstPage()
Navigate to the first page.
goToFirstPage(): voidgoToLastPage()
Navigate to the last page.
goToLastPage(): voidgetCurrentPage()
Get the current page number (1-based).
getCurrentPage(): numbergetPageCount()
Get the total page count.
getPageCount(): numberZoom
zoomIn()
Increase the zoom level.
zoomIn(): voidzoomOut()
Decrease the zoom level.
zoomOut(): voidzoomTo(scale)
Set zoom to a specific scale value (e.g., 1.0 = 100%, 2.0 = 200%).
zoomTo(scale: number): voidsetFitMode(mode)
Set the document fit mode.
setFitMode(mode: 'none' | 'width' | 'page'): void| Mode | Description |
|---|---|
'none' | No automatic fitting |
'width' | Fit to container width |
'page' | Fit entire page in view |
getZoom()
Get the current zoom scale value.
getZoom(): numberRotation
rotateCW()
Rotate the document clockwise by 90 degrees.
rotateCW(): voidrotateCCW()
Rotate the document counter-clockwise by 90 degrees.
rotateCCW(): voidgetRotation()
Get the current rotation in degrees (0, 90, 180, or 270).
getRotation(): numberSearch
openSearch()
Open the search bar.
openSearch(): voidcloseSearch()
Close the search bar.
closeSearch(): voidPrint and Download
print()
Print the document using the browser's print dialog.
print(): voiddownload()
Download the document. Requires the download feature to be enabled.
download(): voidFullscreen
enterFullscreen()
Enter fullscreen mode.
enterFullscreen(): voidexitFullscreen()
Exit fullscreen mode.
exitFullscreen(): voidtoggleFullscreen()
Toggle fullscreen mode.
toggleFullscreen(): voidSignature Panel
openSignaturePanel()
Open the signature details panel.
openSignaturePanel(): voidcloseSignaturePanel()
Close the signature details panel.
closeSignaturePanel(): voidAccessibility
setFontScale(scale)
Set the UI font scale for the viewer. Affects all text, toolbar buttons, and panel heights.
setFontScale(scale: 'compact' | 'default' | 'large' | 'extra-large'): void| Scale | Multiplier | Description |
|---|---|---|
compact | 0.88x | Smaller UI for information density |
default | 1.00x | Standard size |
large | 1.15x | Larger text for readability |
extra-large | 1.30x | Maximum readability |
getFontScale()
Get the current UI font scale.
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.
revalidate(): Promise<VerificationResult | null>Returns: Promise<VerificationResult | null> — the updated verification result, or null if no document is loaded.
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.
on(event: string, handler: (...args: unknown[]) => void): () => voidSupported events:
| Event | Payload | Description |
|---|---|---|
pageChange | number | Current page changed |
zoomChange | number | Zoom scale changed |
themeChange | 'light' | 'dark' | Theme mode changed |
rotationChange | number | Rotation changed |
fullscreenChange | boolean | Fullscreen state changed |
fontScaleChange | string | UI font scale changed |
documentLoaded | { pageCount: number; fileName: string } | Document finished loading |
verified | VerificationResult | Verification completed |
error | LoadError | Error occurred (object with name and message) |
Example:
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.
getVerificationResult(): VerificationResult | nullgetSignatures()
Get the current signature list. Returns an empty array if no document is loaded.
getSignatures(): PdfSignature[]Callbacks
Callbacks can be provided in VerifyKitOptions as an alternative to the event system:
| Callback | Signature | Description |
|---|---|---|
onVerified | (result: VerificationResult) => void | Called when signature verification completes |
onError | (error: LoadError) => void | Called when an error occurs |
onDocumentLoaded | (info: { pageCount: number; fileName: string }) => void | Called when the PDF is loaded in the viewer |
onPageChange | (page: number) => void | Called when the current page changes |
onZoomChange | (scale: number) => void | Called when the zoom level changes |
onThemeChange | (mode: 'light' | 'dark') => void | Called when the theme mode changes |
Example:
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.
interface LoadError {
name: LoadErrorName
message: string
}
type LoadErrorName =
| 'InvalidPDFException'
| 'MissingPDFException'
| 'UnexpectedResponseException'
| 'PasswordException'
| 'AbortException'
| 'FormatError'
| 'NetworkError'
| 'UnsupportedInputError'
| 'VerificationError'
| 'UnknownErrorException'Example:
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
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()