PDFDocument.fromFile()
Load a PDF from a
File object (file picker).static methodLoadingsince 1.0.0
Signature
static fromFile(file: File, options?: OpenOptions): Promise<PDFDocument>
Parameters
| Parameter | Type | Description |
|---|---|---|
| file | File | A File, from a file picker or a drop. |
| 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
input.addEventListener('change', async () => { const [file] = input.files ?? []; if (file) doc = await PDFDocument.fromFile(file); });