Convert image to PDF in Node.js

Nutrient Node.js SDK enables you to convert images to PDF documents. For more information on the supported image formats, see the list of supported file types.

The example below loads an image and exports it to a PDF:

import fs from "node:fs";
import { load } from "@pspdfkit/nodejs";

const pngImage = fs.readFileSync("source.png");

const instance = await load({ document: pngImage });
const buffer = await instance.exportPDF();

fs.writeFileSync("converted.pdf", Buffer.from(buffer));
await instance.close();