PDFPageRemover – Remove Pages from PDF
/* — CSS SEPARATION START — */
@import url(‘https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap’);:root {
–primary: #EF4444; /* Red-500 (Deletion Theme) */
–bg-dark: #0F172A;
}body {
font-family: ‘Inter’, sans-serif;
transition: background-color 0.3s, color 0.3s;
}/* Page Card Styles */
.page-card {
transition: all 0.3s ease;
position: relative;
cursor: pointer;
}
.page-card:hover {
transform: translateY(-3px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
/* Deleted State */
.page-card.deleted .page-image {
opacity: 0.3;
filter: grayscale(100%);
}
.page-card.deleted::after {
content: ‘\f2ed’; /* FontAwesome Trash */
font-family: ‘Font Awesome 6 Free’;
font-weight: 900;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 3rem;
color: #EF4444;
pointer-events: none;
z-index: 10;
}
.page-card.deleted .status-badge {
background-color: #EF4444;
color: white;
content: “Removed”;
}/* Loading Spinner */
.loader {
border: 3px solid #f3f3f3;
border-radius: 50%;
border-top: 3px solid #EF4444;
width: 20px;
height: 20px;
animation: spin 1s linear infinite;
}@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}/* Dropzone Active */
.dropzone-active {
border-color: #EF4444 !important;
background-color: rgba(239, 68, 68, 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: ‘#EF4444’,
}
}
}
}
// PDF.js Worker
pdfjsLib.GlobalWorkerOptions.workerSrc = ‘https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js’;
Remove unwanted pages from your documents visually. Click the pages you want to discard, then save the new file.
Drop PDF Document Here We’ll extract pages for you to review
Select File
0 Pages Total • 0 Removed
Reset All
Download Updated PDF
Click on pages to mark them for deletion.
// — JAVASCRIPT SEPARATION START —// DOM Elements
const dropzone = document.getElementById(‘dropzone’);
const fileInput = document.getElementById(‘fileInput’);
const loadingArea = document.getElementById(‘loading-area’);
const editorArea = document.getElementById(‘editor-area’);
const pagesGrid = document.getElementById(‘pages-grid’);
const pageCountEl = document.getElementById(‘page-count’);
const removedCountEl = document.getElementById(‘removed-count’);
const btnSave = document.getElementById(‘btn-save’);let originalPdfBytes = null;
let originalFileName = “document”;
let pagesToRemove = new Set(); // Set of page numbers (1-based) to remove
let totalPages = 0;
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 —function handleFile(file) {
if (file.type !== ‘application/pdf’) {
alert(‘Please upload a valid PDF file.’);
return;
}originalFileName = file.name.replace(‘.pdf’, ”);
dropzone.classList.add(‘hidden’);
loadingArea.classList.remove(‘hidden’);const reader = new FileReader();
reader.onload = async function(e) {
originalPdfBytes = new Uint8Array(e.target.result);
await renderPages(originalPdfBytes);
};
reader.readAsArrayBuffer(file);
}async function renderPages(pdfBytes) {
const loadingTask = pdfjsLib.getDocument(pdfBytes);
const pdf = await loadingTask.promise;
totalPages = pdf.numPages;
pageCountEl.innerText = totalPages;
pagesToRemove.clear();
updateCounts();
pagesGrid.innerHTML = ”;for (let i = 1; i toggleDelete(i);
card.innerHTML = `
`;
pagesGrid.appendChild(card);
}loadingArea.classList.add(‘hidden’);
editorArea.classList.remove(‘hidden’);
}function toggleDelete(pageNum) {
const card = document.getElementById(`page-card-${pageNum}`);
const statusIcon = card.querySelector(‘.status-icon’);if (pagesToRemove.has(pageNum)) {
// Restore
pagesToRemove.delete(pageNum);
card.classList.remove(‘deleted’);
statusIcon.classList.remove(‘text-red-500’);
statusIcon.classList.add(‘text-gray-300’);
} else {
// Delete
pagesToRemove.add(pageNum);
card.classList.add(‘deleted’);
statusIcon.classList.remove(‘text-gray-300’);
statusIcon.classList.add(‘text-red-500’);
}
updateCounts();
}function restoreAll() {
pagesToRemove.clear();
document.querySelectorAll(‘.page-card’).forEach(card => {
card.classList.remove(‘deleted’);
const icon = card.querySelector(‘.status-icon’);
icon.classList.remove(‘text-red-500’);
icon.classList.add(‘text-gray-300’);
});
updateCounts();
}function updateCounts() {
removedCountEl.innerText = `${pagesToRemove.size} Removed`;
if (pagesToRemove.size === totalPages) {
btnSave.disabled = true;
btnSave.classList.add(‘opacity-50’, ‘cursor-not-allowed’);
btnSave.title = “Cannot delete all pages”;
} else {
btnSave.disabled = false;
btnSave.classList.remove(‘opacity-50’, ‘cursor-not-allowed’);
btnSave.title = “”;
}
}async function savePDF() {
if (pagesToRemove.size === totalPages) {
alert(“You cannot delete all pages. Please keep at least one.”);
return;
}const { PDFDocument } = PDFLib;
try {
const pdfDoc = await PDFDocument.load(originalPdfBytes);
const newPdf = await PDFDocument.create();
const pageCount = pdfDoc.getPageCount();
const keepPageIndices = [];for (let i = 0; i newPdf.addPage(page));const pdfBytes = await newPdf.save();
const blob = new Blob([pdfBytes], { type: ‘application/pdf’ });
const url = URL.createObjectURL(blob);
const link = document.createElement(‘a’);
link.href = url;
link.download = `${originalFileName}_edited.pdf`;
link.click();
} catch (err) {
console.error(err);
alert(‘Error saving PDF.’);
}
}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 —
PDF Page Remover: Overview and Usage Tips Use the PDF Page Remover utility for tasks involving PDF documents. Review the tool interface for supported inputs and settings. For file-based tasks, keep a copy of your original file and check the output before using it.
Steps to get started Read the supported formats or input requirements shown in the tool. Choose the available options appropriate to your task. Run the tool and review its result for accuracy and quality. Related resources For another way to remove unwanted pages, try Delete Pages From PDF . To combine remaining pages with another file, use Merge PDF .