Discover Why I Love PDF Tools for Your Document Needs

 

'; return; } // Parse pages to remove (assume comma-separated, pages starting at 1) let pagesToRemove = []; if (pagesInput.trim() !== '') { pagesToRemove = pagesInput.split(',') .map(num => parseInt(num.trim(), 10)) .filter(num => !isNaN(num) && num > 0); } // Show spinner and disable button spinnerArea.style.display = 'block'; removeButton.disabled = true; try { const arrayBuffer = await file.arrayBuffer(); const pdfDoc = await PDFDocument.load(arrayBuffer); const totalPages = pdfDoc.getPageCount(); // Convert pages to remove into zero-indexed array const removeIndices = pagesToRemove.map(num => num - 1); // Create a new PDF document with remaining pages const newPdf = await PDFDocument.create(); for (let i = 0; i < totalPages; i++) { if (!removeIndices.includes(i)) { const [copiedPage] = await newPdf.copyPages(pdfDoc, [i]); newPdf.addPage(copiedPage); } } const pdfBytes = await newPdf.save(); const blob = new Blob([pdfBytes], { type: 'application/pdf' }); const url = URL.createObjectURL(blob); // Create a download link for the new PDF const downloadLink = document.createElement('a'); downloadLink.href = url; downloadLink.download = 'modified.pdf'; downloadLink.className = 'btn btn-outline-primary'; downloadLink.textContent = 'Download Modified PDF'; outputArea.appendChild(downloadLink); alertArea.innerHTML = '

'; } catch (error) { console.error('Error removing pages:', error); alertArea.innerHTML = '

'; } finally { spinnerArea.style.display = 'none'; removeButton.disabled = false; } });

 

PDF Splitter Tool

Remove Pages from PDF Tool

Remove Pages from PDF