PDF to Editable Document Converter

PDF to Editable Document Converter

Drag & drop your PDF here

or

Processing "${file.name}"...

`; const reader = new FileReader(); reader.onload = async (e) => { try { const pdfData = new Uint8Array(e.target.result); const pdf = await window.pdfjsLib.getDocument({ data: pdfData }).promise; let fullText = ''; for (let i = 1; i <= pdf.numPages; i++) { const page = await pdf.getPage(i); const textContent = await page.getTextContent(); const pageText = textContent.items.map(item => item.str).join(' '); fullText += pageText + '\n\n'; } editableContent.value = fullText.trim(); uploadStatus.innerHTML = `

Successfully extracted text from "${file.name}".

`; showTab(1); // Move to edit tab } catch (error) { console.error('Error processing PDF:', error); uploadStatus.innerHTML = `

An error occurred while processing the PDF.

`; } }; reader.readAsArrayBuffer(file); }; // --- Download Logic --- downloadTxtButton.addEventListener('click', () => { const text = editableContent.value; const blob = new Blob([text], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${originalFileName.replace('.pdf', '')}_edited.txt`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }); downloadPdfButton.addEventListener('click', () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const margin = 20; const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - margin * 2; let y = margin; doc.setFont('helvetica', 'bold'); doc.setFontSize(18); doc.text('PDF Conversion Report', pageWidth / 2, y, { align: 'center' }); y += 10; doc.setFontSize(10); doc.setFont('helvetica', 'normal'); doc.setTextColor('#6B7280'); doc.text(`Original File: ${originalFileName}`, pageWidth / 2, y, { align: 'center' }); y += 15; doc.setDrawColor('#E5E7EB').line(margin, y, pageWidth - margin, y); y += 10; doc.setFontSize(14); doc.setFont('helvetica', 'bold'); doc.setTextColor('#374151'); doc.text('Edited Content', margin, y); y += 8; doc.setFontSize(11); doc.setFont('helvetica', 'normal'); doc.setTextColor('#4B5563'); const text = editableContent.value; const splitText = doc.splitTextToSize(text, usableWidth); doc.text(splitText, margin, y); doc.save(`${originalFileName.replace('.pdf', '')}_report.pdf`); }); // --- Initial Setup --- showTab(0); });
Scroll to Top