NPM Package v1.0.0 is Live

Infyn Developer Documentation

Integrate client-side PDF manipulation, image compression, metadata removal, and WASM conversion directly into your React, Next.js, or Vue applications with zero server costs and 100% user privacy.

Getting Started & Installation

Install Infyn using your favorite package manager. The library exports modern ESM, CommonJS, and full TypeScript declarations.

Terminal
# npm
npm install infyn

# pnpm
pnpm add infyn

# yarn
yarn add infyn

Import Strategies

Infyn supports both an all-in-one root import and granular subpaths to optimize bundle size and tree-shaking:

Subpath vs Root Import
// 1. All-in-one import (great for quick scripting)
import { mergePDFs, compressImage, decryptPDF } from "infyn";

// 2. Subpath imports (recommended for minimal bundle sizes)
import { mergePDFs, splitPDF, encryptPDF } from "infyn/pdf";
import { compressImage, convertHeicToJpg, removeExif } from "infyn/image";
infyn/pdf

PDF Manipulation Suite

High-performance, in-browser PDF merging, splitting, page extraction, AES-256 password encryption, and unlocking without sending documents over the wire.

mergePDFs(files)

Merges an array of PDF files, Blobs, ArrayBuffers, or Uint8Arrays in sequential order into a single PDF document.

mergePDFs Example
import { mergePDFs } from "infyn/pdf";

async function handleMerge(pdfFiles: File[]) {
  // Returns Uint8Array of the merged document
  const mergedBytes = await mergePDFs(pdfFiles);
  
  // Wrap in a Blob for instant browser download or preview
  const blob = new Blob([mergedBytes], { type: "application/pdf" });
  const url = URL.createObjectURL(blob);
  
  return url;
}

extractPDFPages(file, pageNumbers) & splitPDF(file)

Extract a subset of pages into a new document, or split all pages into individual standalone documents.

Split & Extraction Example
import { extractPDFPages, splitPDF } from "infyn/pdf";

// Extract pages 1, 3, and 5 into a single 3-page PDF (1-indexed)
const extractedBytes = await extractPDFPages(myPdfFile, [1, 3, 5]);

// Split an entire PDF into separate 1-page documents
const splitPages = await splitPDF(myPdfFile);
// splitPages => [
//   { pageNumber: 1, data: Uint8Array },
//   { pageNumber: 2, data: Uint8Array }
// ]

encryptPDF(file, password) & decryptPDF(file, password)

Protect confidential PDFs with standard AES-256 encryption, or unlock encrypted documents in-memory.

Security & Password Protection Example
import { encryptPDF, decryptPDF, isPDFEncrypted } from "infyn/pdf";

// 1. Check if a document is password protected
const isLocked = await isPDFEncrypted(uploadedFile);

// 2. Encrypt document with a password
const protectedBytes = await encryptPDF(myPdfFile, "superSecretPassword");

// 3. Remove password and unlock PDF
const unlockedBytes = await decryptPDF(encryptedPdfFile, "superSecretPassword");

compressPDF(file, options)

Reduces PDF document size up to 90% via multi-strategy in-browser raster downsampling and structural object stream compaction.

compressPDF Example
import { compressPDF } from "infyn/pdf";

// 1. Compress with Recommended Preset (balanced clarity & size)
const result = await compressPDF(myPdfFile, { preset: "recommended" });

// 2. Compress for Strict Portal Limits (<500 KB or <200 KB)
const targetResult = await compressPDF(myPdfFile, {
  preset: "target",
  targetSizeKb: 500
});

console.log("Original Size:", result.originalSize);
console.log("Compressed Size:", result.compressedSize);
console.log("Savings:", result.savedPercentage + "%");
const compressedBlob = new Blob([result.data], { type: "application/pdf" });
infyn/image

Image Processing Suite

Compress images, decode Apple HEIC photos via WebAssembly, convert formats, and wipe private EXIF/GPS metadata.

compressImage(file, options)

Compresses image file sizes with bicubic canvas downscaling and quality tuning.

compressImage Example
import { compressImage } from "infyn/image";

const result = await compressImage(photoFile, {
  quality: 0.8,         // 0.1 to 1.0
  maxWidth: 1920,       // Automatically scales down if wider
  targetFormat: "image/webp"
});

console.log("Original Size:", result.originalSize);
console.log("Compressed Size:", result.compressedSize);
console.log("Savings:", result.savedPercentage + "%");
console.log("Output Blob:", result.blob);

convertHeicToJpg(file) & removeExif(file)

Decode iPhone HEIC/HEIF images into standard JPEGs and strip GPS coordinates for privacy before upload.

HEIC & EXIF Cleaner Example
import { convertHeicToJpg, removeExif, convertImage } from "infyn/image";

// 1. Convert iPhone HEIC photo to standard JPEG
const jpegBlob = await convertHeicToJpg(iphonePhotoFile);

// 2. Wipe EXIF & GPS location metadata
const anonymizedBlob = await removeExif(photoFile);

// 3. Universal format converter (PNG -> WebP)
const webpBlob = await convertImage(pngFile, "image/webp", 0.9);

generateQRCode(text, options)

Generate high-resolution PNG bytes or vector SVG strings in-browser with customizable colors and error correction.

QR Code Generator Example
import { generateQRCode } from "infyn/image";

// 1. Generate High-Res PNG bytes (512px - 4000px)
const pngBytes = await generateQRCode("https://infyn.software", {
  width: 1024,
  errorCorrectionLevel: "H",
  colorDark: "#111111",
  colorLight: "#FFFFFF",
  format: "png"
});

// 2. Generate crisp vector SVG markup
const svgString = await generateQRCode("WIFI:T:WPA;S:MyWiFi;P:Secret;;", {
  format: "svg"
});
React / Next.js

Embedding Infyn in React Apps

Here is a complete, copy-pasteable React component demonstrating a complete client-side PDF merger widget using Infyn:

components/PDFMergerWidget.tsx
"use client";

import React, { useState } from "react";
import { mergePDFs } from "infyn/pdf";

export function PDFMergerWidget() {
  const [isProcessing, setIsProcessing] = useState(false);
  const [downloadUrl, setDownloadUrl] = useState<string | null>(null);

  const handleFiles = async (e: React.ChangeEvent<HTMLInputElement>) => {
    if (!e.target.files || e.target.files.length < 2) {
      alert("Please select 2 or more PDF files.");
      return;
    }

    setIsProcessing(true);
    try {
      const filesArray = Array.from(e.target.files);
      const mergedBytes = await mergePDFs(filesArray);
      
      const blob = new Blob([mergedBytes], { type: "application/pdf" });
      setDownloadUrl(URL.createObjectURL(blob));
    } catch (err: any) {
      alert("Failed to merge PDFs: " + err.message);
    } finally {
      setIsProcessing(false);
    }
  };

  return (
    <div className="p-6 border rounded-2xl bg-white space-y-4">
      <h3 className="font-bold text-lg">In-Browser PDF Merger</h3>
      <input 
        type="file" 
        multiple 
        accept="application/pdf" 
        onChange={handleFiles} 
      />
      
      {isProcessing && <p className="text-sm text-gray-500">Merging PDFs locally...</p>}
      
      {downloadUrl && (
        <a 
          href={downloadUrl} 
          download="merged.pdf"
          className="inline-block px-4 py-2 bg-black text-white font-bold rounded-xl text-sm"
        >
          Download Merged PDF
        </a>
      )}
    </div>
  );
}
CLI & Node.js

Node.js & Scripting Usage

Infyn's PDF utilities (`infyn/pdf`) are fully compatible with Node.js and script automations using standard `Buffer` and `fs`:

scripts/merge.js
const fs = require("fs");
const { mergePDFs } = require("infyn/pdf");

async function main() {
  const doc1 = fs.readFileSync("report1.pdf");
  const doc2 = fs.readFileSync("report2.pdf");

  console.log("Merging PDFs...");
  const mergedBytes = await mergePDFs([doc1, doc2]);

  fs.writeFileSync("combined-report.pdf", Buffer.from(mergedBytes));
  console.log("Saved combined-report.pdf successfully!");
}

main();

Zero-Upload Privacy Architecture

How Infyn ensures total client-side execution without compromising performance.

WebAssembly & Canvas

Decoders and raster engines run in WebAssembly bundles and hardware-accelerated 2D HTML5 Canvas contexts.

In-Memory WebCrypto

AES-256 PDF encryption and key derivation execute natively via the browser's cryptographic subsystem.