PDFkind
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)

JavaScript
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
}
OptionTypeDescription
maxstring or numberRequired. Same format as data-pdfkind-max: 5MB, 500KB or bytes.
elElementOptional. 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:

reasonMeaning
too-bigEven reduced, the file is over the limit.
unsupportedNot a PDF or an image the helper can reduce.
cancelThe visitor closed the window.
unavailableThe PDFkind window didn’t load within 8 seconds.
timeoutProcessing took longer than 3 minutes.
failedThe file is damaged, or something else went wrong.
bad-callCalled 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.

JavaScript
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