Getting Started & Installation
Install Infyn using your favorite package manager. The library exports modern ESM, CommonJS, and full TypeScript declarations.
# 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:
// 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";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.
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.
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.
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");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.
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.
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);Embedding Infyn in React Apps
Here is a complete, copy-pasteable React component demonstrating a complete client-side PDF merger widget using Infyn:
"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>
);
}Node.js & Scripting Usage
Infyn's PDF utilities (`infyn/pdf`) are fully compatible with Node.js and script automations using standard `Buffer` and `fs`:
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.