Generate PDFs from Images Using JavaScript

When calling PSPDFKit#load() in Standalone mode, you can pass either an array buffer or a URL to the image into the document option. Or, when calling PSPDFKit#load() in Server mode, you can pass the documentId. After doing this, PSPDFKit for Web will open the image file as if it were a PDF document:

const res = await fetch("https://example.com/example.tiff");
const imageArrayBuffer = await res.arrayBuffer();
PSPDFKit.load({
  document: imageArrayBuffer
  // Other options.
});

Image documents can be loaded the same way in headless mode by providing the headless option:

PSPDFKit.load({
  document: image,
  headless: true
});

For more information on loading options, follow our guides on importing a PDF document.

Exporting Image Documents

Image documents can be exported as PDF documents by using Instance#exportPDF() and triggering a download, as explained in the Save a Document to Local Storage guide.

We use cookies to improve your experience and for marketing. Learn more in our privacy policy.