🔒 Files never leave your device. All PDF processing happens 100% locally in your browser RAM.

Images to PDF Utility

The imagesToPDF function compiles an array of image files or buffers (JPEG/PNG) into a single PDF document. It scales pages to match individual image sizes.

API Signature

function imagesToPDF(
  images: (File | Blob | ArrayBuffer | Uint8Array)[]
): Promise<Uint8Array>

Parameters

  • images: An array of image files, blobs, or buffers.

Code Example

import { imagesToPDF } from "@manojcoder/pdf-utils";

async function compilePhotos(files: File[]) {
  try {
    const pdfBytes = await imagesToPDF(files);
    const blob = new Blob([pdfBytes], { type: "application/pdf" });
    const url = URL.createObjectURL(blob);
    
    // Open in browser
    window.open(url);
  } catch (error) {
    console.error("Compilation failed. Ensure all files are valid JPEGs/PNGs.", error);
  }
}

Dimensions Match: Each page size inside the compiled PDF matches the native width and height of the corresponding image.