Standalone functions the package exports beside the classes. Three draw the document states before and around a document, in place rather than as a browser prompt or a status line: a drop target before any file is chosen, a password prompt, and a load-error card. They take the viewer's locale and toolbar.icons as options.locale and options.icons, so a card shown before the viewer exists speaks its language and draws its icons. createPasswordPrompt and createLoadError return { element, destroy() }; createDropZone returns { element, open(), destroy() }.
Four are geometry helpers for callers that think in edges or quads. Every point and rectangle the API takes or gives is in page space: PDF points (1/72 inch), the origin at the page's bottom-left corner, y growing upwards — the page's own coordinates, as the file holds them and every reader shares them, unturned by the page's rotation. Point is { x, y }, Size is { width, height }, Rect is both (its bottom-left corner and its size; width and height never negative), Quad is { topLeft, topRight, bottomLeft, bottomRight } (one line a text mark covers, its corners named as Acrobat writes them) and RectEdges is { left, bottom, right, top } (how a PDF file stores a rectangle). An annotation's rect, a form field's, a text block's bounds, a search match's rects and a page's boxes are all Rects; a text mark's lines are Quads. A rect given to the API is checked: four finite numbers, width and height not negative, or INVALID_ARGUMENT. To convert between page space and the viewer's CSS pixels, use viewer.pageToClient and viewer.clientToPage.
import { createDropZone } from'@kernstra/pdf-web-sdk';
const zone = createDropZone(container, {
onFile: (file) => {
voidopenPdf(file);
}, // a dropped or chosen PDFonReject: (file) => {
/* not a PDF */
}, // optionaltitle: 'Drop a PDF here', // optionalnote: 'Everything happens in this browser. Nothing is uploaded.', // optionalaction: 'Choose a file', // optionallocale: { lang: 'de', translations: { de: myGerman } }, // optional: the viewer's localeicons: { dropZoneFile: myFileIconSvg }, // optional: the viewer's toolbar.icons
});
zone.open(); // opens the file picker — wire it to Ctrl+O
zone.destroy(); // once a document is open
The viewer before a document. A host mounts the viewer and, until a file arrives, has nothing to show but a blank box; this is that box — a drop target, a file picker, and the privacy line.
Parameter
Type
Description
container
HTMLElement
Where the box is mounted — the element the viewer will later use.
options
DropZoneOptions
{ onFile, onReject?, title?, note?, action?, locale?, icons? }. onFile(file) receives a dropped or chosen PDF; onReject(file) a file that is not a PDF. title, note and action are the words shown; locale is the viewer's locale and icons its toolbar.icons.
ReturnsDropZone{ element, open(), destroy() } — open() opens the file picker, for a host shortcut such as Ctrl+O; destroy() once a document is open.
"This document is protected · Enter the password to open it." — shown in place when a load rejects with PASSWORD_ERROR. A wrong password (resolve false from onUnlock) shakes the field and says so.
Parameter
Type
Description
container
HTMLElement
Where the prompt is mounted.
options
PasswordPromptOptions
{ onUnlock, onCancel?, name?, locale?, icons? }. onUnlock(password) returns true / false directly or as a promise — false shakes the field and says the password was wrong; onCancel() when the user gives up; name is the file's name to show; locale and icons as for createDropZone.
The load-failure card: plain language first ("The PDF appears to be damaged or incomplete."), the SDKError code second and small (the error's own message is its tooltip), then Try another file / Retry.
Parameter
Type
Description
container
HTMLElement
Where the card is mounted.
options
LoadErrorOptions
{ error, onRetry?, onChooseAnother?, locale?, icons? }. error is what the load rejected with (an SDKError, or anything else); onRetry() and onChooseAnother() back the Retry and Try another file buttons; locale and icons as for createDropZone.