Web SDKv1.0.0

PDFDocument.fromBytes()

Load a PDF from a Uint8Array.
static methodLoadingsince 1.0.0

Signature

static fromBytes(bytes: Uint8Array, options?: OpenOptions): Promise<PDFDocument>

Parameters

ParameterTypeDescription
bytesUint8ArrayThe PDF bytes.
options?OpenOptions{ password? } — the password of an encrypted file.

Returns

Promise<PDFDocument>

Throws

  • NOT_INITIALIZED — Kernstra.init() has not resolved.
  • FORMAT_ERROR — not a PDF, or a corrupt one.
  • PASSWORD_ERROR — a password is required, or the one supplied is wrong.
  • SECURITY_ERROR — encrypted with a security handler the SDK cannot open.
  • LICENSE_REQUIRED — opened under a stopped license: no document opens.
  • OUT_OF_MEMORY — the SDK could not allocate the memory the file needs.
  • ENGINE_FAILED — the SDK stopped on an unrecoverable fault (fatal).

Example

TypeScript
const bytes = new Uint8Array(await (await fetch('/terms.pdf')).arrayBuffer());
const doc = await PDFDocument.fromBytes(bytes);

More in PDFDocument