Developer docs: JavaScript API
Upload helper
JavaScript API
Reduce a PDF or image to a size limit from your own code with PDFkind.fit(file, { max }), and handle every outcome.
The script adds a global PDFkind object. Use it when files come from somewhere the automatic mode doesn’t see: paste, a camera, a custom picker.
PDFkind.fit(file, options)
try {
const small = await PDFkind.fit(file, { max: '5MB' });
upload(small);
} catch (err) {
if (err.reason === 'too-big') alert('This file is too large, even reduced.');
else upload(file); // fall back to the original
}| Option | Type | Description |
|---|---|---|
max | string or number | Required. Same format as data-pdfkind-max: 5MB, 500KB or bytes. |
el | Element | Optional. Its data-lang (or a parent’s) sets the window language. |
It resolves with a File: the reduced one, the converted JPG for HEIC photos, or the original when it already fits (no window opens then). It rejects with an error whose reason is one of:
| reason | Meaning |
|---|---|
too-big | Even reduced, the file is over the limit. |
unsupported | Not a PDF or an image the helper can reduce. |
cancel | The visitor closed the window. |
unavailable | The PDFkind window didn’t load within 8 seconds. |
timeout | Processing took longer than 3 minutes. |
failed | The file is damaged, or something else went wrong. |
bad-call | Called without a File or without max. |
PDFkind.mount(root)
Turns data-pdfkind-tool elements into tools. It runs by itself on page load; call it again after adding tools later, for example in a single-page app. root is optional and defaults to the whole page.
container.innerHTML = '<div data-pdfkind-tool="split-pdf"></div>';
PDFkind.mount(container);PDFkind.version
The script version, currently 3. Handy to check the script is loaded: type PDFkind.version in the browser console.
Last updated November 3, 2026 · Questions: contact@pdfkind.com