<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: resizekb</title>
    <description>The latest articles on DEV Community by resizekb (@resizekb).</description>
    <link>https://dev.to/resizekb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3973491%2Fe8655624-5d64-42d3-a67f-183cb85645ef.png</url>
      <title>DEV Community: resizekb</title>
      <link>https://dev.to/resizekb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/resizekb"/>
    <language>en</language>
    <item>
      <title>How I Built a Browser-Based File Compression Tool for India Using Canvas API and pdf-lib — No Backend Needed</title>
      <dc:creator>resizekb</dc:creator>
      <pubDate>Mon, 08 Jun 2026 06:21:09 +0000</pubDate>
      <link>https://dev.to/resizekb/how-i-built-a-browser-based-file-compression-tool-for-india-using-canvas-api-and-pdf-lib-no-2db7</link>
      <guid>https://dev.to/resizekb/how-i-built-a-browser-based-file-compression-tool-for-india-using-canvas-api-and-pdf-lib-no-2db7</guid>
      <description>&lt;p&gt;I built ResizeKB — a free image and PDF resizer built specifically for Indian users. 25+ tools. Zero server uploads. Pure HTML, CSS, JavaScript. Here's how and why.&lt;/p&gt;

&lt;p&gt;The Problem&lt;br&gt;
Every Indian applying for government jobs, exams, or bank accounts hits the same wall — portals with strict KB limits rejecting documents.&lt;br&gt;
UPSC wants photo under 300KB. SSC wants under 50KB. Banks need Aadhaar PDF under 500KB. Every portal is different. Every rejection wastes someone's time and opportunity.&lt;br&gt;
Most people have no idea how to resize to an exact KB. They either give up or use random tools that upload their Aadhaar and PAN card to unknown servers.&lt;br&gt;
I built a tool that solves this in one click — with zero server upload.&lt;/p&gt;

&lt;p&gt;The Tech Stack&lt;br&gt;
No framework. No backend. No database.&lt;/p&gt;

&lt;p&gt;Canvas API for image processing&lt;br&gt;
pdf-lib for PDF compression&lt;br&gt;
Vanilla JavaScript only&lt;br&gt;
Cloudflare Pages for hosting — free, global CDN, auto deploys from GitHub&lt;/p&gt;

&lt;p&gt;Total infrastructure cost: ₹1,162 per year for the domain. Everything else free.&lt;/p&gt;

&lt;p&gt;Image Compression — The Binary Search Algorithm&lt;br&gt;
The core challenge is compressing to an exact KB target without over-compressing. Most tools use a fixed quality setting like 60% which destroys image quality.&lt;br&gt;
The right approach is binary search on JPEG quality:&lt;br&gt;
javascriptasync function compressToTargetSize(file, targetKB) {&lt;br&gt;
  const targetBytes = targetKB * 1024;&lt;br&gt;
  let low = 0.1;&lt;br&gt;
  let high = 1.0;&lt;br&gt;
  let result = null;&lt;/p&gt;

&lt;p&gt;const img = await loadImage(file);&lt;br&gt;
  const canvas = document.createElement('canvas');&lt;br&gt;
  canvas.width = img.width;&lt;br&gt;
  canvas.height = img.height;&lt;br&gt;
  const ctx = canvas.getContext('2d');&lt;br&gt;
  ctx.drawImage(img, 0, 0);&lt;/p&gt;

&lt;p&gt;while (high - low &amp;gt; 0.01) {&lt;br&gt;
    const mid = (low + high) / 2;&lt;br&gt;
    const blob = await canvasToBlob(canvas, 'image/jpeg', mid);&lt;br&gt;
    if (blob.size &amp;lt;= targetBytes) {&lt;br&gt;
      result = blob;&lt;br&gt;
      low = mid;&lt;br&gt;
    } else {&lt;br&gt;
      high = mid;&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
  return result;&lt;br&gt;
}&lt;br&gt;
This finds the highest quality setting that still hits your target KB. Result is the sharpest possible image at that file size — never over-compressed.&lt;/p&gt;

&lt;p&gt;PDF Compression — How It Works&lt;br&gt;
pdf-lib is an open source JavaScript library that manipulates PDFs entirely in the browser. No server needed.&lt;br&gt;
javascriptimport { PDFDocument } from 'pdf-lib';&lt;/p&gt;

&lt;p&gt;async function compressPDF(file, targetKB) {&lt;br&gt;
  const arrayBuffer = await file.arrayBuffer();&lt;br&gt;
  const pdfDoc = await PDFDocument.load(arrayBuffer);&lt;br&gt;
  const pages = pdfDoc.getPages();&lt;br&gt;
  const totalPages = pages.length;&lt;/p&gt;

&lt;p&gt;// Calculate target KB per page&lt;br&gt;
  const targetPageKb = (targetKB / totalPages) * 0.9;&lt;/p&gt;

&lt;p&gt;// Rasterize each page to canvas at calculated DPI&lt;br&gt;
  // Recompress as JPEG at target quality&lt;br&gt;
  // Embed back into PDF structure&lt;/p&gt;

&lt;p&gt;const compressed = await pdfDoc.save();&lt;br&gt;
  return new Blob([compressed], { type: 'application/pdf' });&lt;br&gt;
}&lt;br&gt;
Works best on image-heavy PDFs like scanned documents. Text-only PDFs are already compressed at the font layer — browser tools can't reduce them further, so ResizeKB detects this and tells the user instead of pretending it worked.&lt;/p&gt;

&lt;p&gt;Privacy — Why It Matters&lt;br&gt;
Most online tools upload your file to their servers. For Indian users this is a real risk — Aadhaar contains biometric data, address, 12-digit identity number. PAN card contains financial identity.&lt;br&gt;
ResizeKB processes everything locally. You can verify this yourself — open browser developer tools → Network tab → upload a file → you'll see zero outgoing file transfer requests.&lt;br&gt;
When you close the tab, everything is gone.&lt;/p&gt;

&lt;p&gt;Browser Compatibility Considerations&lt;br&gt;
A few things I ran into building this:&lt;br&gt;
Canvas API toBlob() is async but older browsers handle it differently — use a Promise wrapper for consistency.&lt;br&gt;
pdf-lib works well for image-heavy PDFs but has limitations with encrypted PDFs. Password-protected Aadhaar PDFs need to be unlocked first — I handle this with a user-facing message rather than silently failing.&lt;br&gt;
Mobile performance — Canvas operations are CPU-intensive. For large images on low-end Android phones, I added a progress indicator so users don't think it crashed.&lt;br&gt;
File size detection — always compare compressed size to original before downloading. If compressed is larger than original (happens with already-optimized files), return the original with a clear message.&lt;/p&gt;

&lt;p&gt;What I'd Do Differently&lt;br&gt;
WebAssembly-based PDF compression would be significantly faster and produce better results than pure JavaScript pdf-lib. MozJPEG via WASM produces 20-30% smaller files at the same visual quality. Future upgrade.&lt;br&gt;
WebP output support — WhatsApp and modern browsers handle WebP well. Smaller files, better quality. Added to roadmap.&lt;/p&gt;

&lt;p&gt;Results — Week 1&lt;/p&gt;

&lt;p&gt;212 pages discovered by Google within 24 hours of sitemap submission&lt;br&gt;
Live on resizekb.com&lt;br&gt;
Listed on Product Hunt and SaaSHub on launch day&lt;br&gt;
Referral traffic coming in from Quora answers on day 1&lt;/p&gt;

&lt;p&gt;Try It&lt;br&gt;
resizekb.com — free, no account, no watermark, works on mobile.&lt;br&gt;
Source is private for now but happy to answer technical questions in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>productivity</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
