Extract Signature Data From PDF (JavaScript)
Use this guide to produce the two values required by POST /v1/signature/verify:
- Document hash as uppercase hex (
hash) - PKCS7 signature as Base64 (
signature)
The extractor supports PDFs with one or more signatures and returns one { signature, hash } pair per detected signature object.
Prerequisites
- Signed PDF file available as bytes (
Uint8Array) - JavaScript runtime that supports ES modules
1. Add the extractor helper
Download and include:
2. Extract verification inputs
import { readFile } from "node:fs/promises";
import { SignatureExtractor } from "./SignatureExtractor.js";
const pdfPath = "./sample-signed.pdf";
const pdfBytes = new Uint8Array(await readFile(pdfPath));
const extractor = new SignatureExtractor(pdfBytes);
const entries = extractor.extract();
for (const [index, entry] of entries.entries()) {
console.log(`Signature ${index + 1}`);
console.log("hash:", entry.hash);
console.log("signature:", entry.signature);
}
Output shape:
[
{
"hash": "A1B2...",
"signature": "MII...="
}
]
3. Validate output format
Before calling the API, verify:
hashcontains only hex characters and is uppercasesignatureis Base64 encoded- At least one entry was extracted from the signed PDF
4. Submit to Document Validator
Use each { hash, signature } pair as an item in your request body:
Limitations
This helper is intentionally minimal and does not implement full PDF parsing. It is designed to extract signature data for verification workflows and assumes standard PDF signature object structures.