PDFResizer200 – Resize PDF to 200KB
/* — CSS SEPARATION START — */
@import url(‘https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap’);:root {
–primary: #6366F1; /* Indigo-500 */
–bg-dark: #0F172A;
}body {
font-family: ‘Inter’, sans-serif;
transition: background-color 0.3s, color 0.3s;
}/* Progress Bar Striping */
.progress-bar-striped {
background-image: linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
background-size: 1rem 1rem;
animation: progress-bar-stripes 1s linear infinite;
}
@keyframes progress-bar-stripes {
0% { background-position: 1rem 0; }
100% { background-position: 0 0; }
}/* Dropzone Active */
.dropzone-active {
border-color: #6366F1 !important;
background-color: rgba(99, 102, 241, 0.05) !important;
transform: scale(1.01);
}/* Dark Mode */
.dark body {
background-color: var(–bg-dark);
color: #F9FAFB;
}
.dark .card {
background-color: #1E293B;
border-color: #334155;
}
/* — CSS SEPARATION END — */
tailwind.config = {
darkMode: ‘class’,
theme: {
extend: {
colors: {
primary: ‘#6366F1’,
}
}
}
}
// Initialize PDF.js Worker
pdfjsLib.GlobalWorkerOptions.workerSrc = ‘https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js’;
Target: 200KB or less
Smartly scales and compresses PDF content to fit under 200KB. Perfect for applications and legal uploads.
Drop PDF File Here We’ll resize it to ~200KB
Select PDF
Done!
Could not reach exactly 200KB. This is the smallest possible size.
Privacy Note: Your PDF is processed locally in your browser. We do not upload your document to any server.
// — JAVASCRIPT SEPARATION START —// DOM Elements
const dropzone = document.getElementById(‘upload-stage’);
const processingStage = document.getElementById(‘processing-stage’);
const resultsStage = document.getElementById(‘results-stage’);
const fileInput = document.getElementById(‘fileInput’);
const progressBar = document.getElementById(‘progress-bar’);
const progressText = document.getElementById(‘progress-text’);
const sizeOriginal = document.getElementById(‘size-original’);
const sizeNew = document.getElementById(‘size-new’);
const downloadBtn = document.getElementById(‘download-btn’);
const warningMsg = document.getElementById(‘warning-msg’);
const canvas = document.getElementById(‘process-canvas’);
const ctx = canvas.getContext(‘2d’);let currentFile = null;
let isDarkMode = false;// — Event Listeners —
dropzone.addEventListener(‘click’, () => fileInput.click());
dropzone.addEventListener(‘dragover’, (e) => { e.preventDefault(); dropzone.classList.add(‘dropzone-active’); });
dropzone.addEventListener(‘dragleave’, () => dropzone.classList.remove(‘dropzone-active’));
dropzone.addEventListener(‘drop’, (e) => {
e.preventDefault();
dropzone.classList.remove(‘dropzone-active’);
if(e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
});fileInput.addEventListener(‘change’, (e) => {
if(e.target.files.length) handleFile(e.target.files[0]);
});// — Core Functions —async function handleFile(file) {
if (file.type !== ‘application/pdf’) {
alert(‘Please upload a valid PDF file.’);
return;
}
currentFile = file;
// UI Switch
dropzone.classList.add(‘hidden’);
processingStage.classList.remove(‘hidden’);
warningMsg.classList.add(‘hidden’);try {
const arrayBuffer = await file.arrayBuffer();
const pdf = await pdfjsLib.getDocument(arrayBuffer).promise;
const totalPages = pdf.numPages;
const { PDFDocument } = PDFLib;
const newPdf = await PDFDocument.create();
// Target: ~200KB total.
const targetBytes = 200 * 1024;
// Strategy: Dual Reduction
// 1. Reduce Resolution (DPI)
// 2. Reduce Image Quality
// 200KB is tight for multi-page. We start modest.
let scale = 1.0; // 1.0 = 72DPI standard view
let quality = 0.7;
// Dynamic Adjustment
if(totalPages > 10) {
scale = 0.6; // Downscale dimensions
quality = 0.5;
} else if(totalPages > 3) {
scale = 0.8;
quality = 0.6;
}for (let i = 1; i canvas.toBlob(resolve, ‘image/jpeg’, quality));
const imgBuffer = await blob.arrayBuffer();
const jpgImage = await newPdf.embedJpg(imgBuffer);
// Add page. IMPORTANT: We add the page at the ORIGINAL viewport size
// but draw the smaller/compressed image scaled up to fit.
// This maintains print dimensions while reducing file size.
const newPage = newPdf.addPage([viewport.width, viewport.height]);
newPage.drawImage(jpgImage, {
x: 0,
y: 0,
width: viewport.width,
height: viewport.height,
});
}let pdfBytes = await newPdf.save();
// Check if we met target
if (pdfBytes.length > targetBytes) {
warningMsg.classList.remove(‘hidden’);
}const blob = new Blob([pdfBytes], { type: ‘application/pdf’ });
const url = URL.createObjectURL(blob);// Show Results
sizeOriginal.innerText = formatBytes(currentFile.size);
sizeNew.innerText = formatBytes(blob.size);
downloadBtn.href = url;
downloadBtn.download = ‘resized_200kb_’ + currentFile.name;
processingStage.classList.add(‘hidden’);
resultsStage.classList.remove(‘hidden’);} catch (err) {
console.error(err);
alert(“Error resizing PDF.”);
resetApp();
}
}function formatBytes(bytes) {
if (bytes === 0) return ‘0 Bytes’;
const k = 1024;
const sizes = [‘Bytes’, ‘KB’, ‘MB’];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ‘ ‘ + sizes[i];
}function resetApp() {
fileInput.value = ”;
dropzone.classList.remove(‘hidden’);
processingStage.classList.add(‘hidden’);
resultsStage.classList.add(‘hidden’);
progressBar.style.width = ‘0%’;
}function toggleDarkMode() {
isDarkMode = !isDarkMode;
document.documentElement.classList.toggle(‘dark’);
const icon = document.getElementById(‘theme-icon’);
if(isDarkMode) {
icon.classList.remove(‘fa-moon’);
icon.classList.add(‘fa-sun’);
} else {
icon.classList.remove(‘fa-sun’);
icon.classList.add(‘fa-moon’);
}
}// — JAVASCRIPT SEPARATION END —
About the Resize PDF to 200KB tool The Resize PDF to 200KB page is part of Articles Stock’s online utilities collection. Use the tool above for the task described in its interface, and check the available file types, settings and output before proceeding. This utility relates to document conversion and PDF workflows.
How to use this tool Review the tool’s supported input and options. Select or enter the required input and choose the settings that suit your task. Run the tool and check the result before saving or sharing it. Related online tools Compress PDF and Word to PDF can help with related tasks.