PDF Document to Word and excel Converter

PDF Document to Word and excel Converter

📄 CMA Knowledge Converter

Professional Document Conversion Suite by cmaknowledge.in

🔒 100% Private ⚡ 6 Conversion Types 💯 Free Forever

Powered by cmaknowledge.in

📁

Drag & Drop Your File Here

or browse from your device

Max size: 150 MB
Ready...
`; downloadFile(['\ufeff', html], `${baseName}_converted.doc`, 'application/msword'); progressBar.style.width = '100%'; } catch (error) { throw new Error('PDF to Word failed: ' + error.message); } } // 3. WORD TO PDF - WITH PROFESSIONAL MARGINS async function convertWordToPdf(baseName) { statusText.textContent = '📄 Converting Word to PDF...'; progressBar.style.width = '20%'; try { const arrayBuffer = await selectedFile.arrayBuffer(); const result = await mammoth.convertToHtml({ arrayBuffer }); progressBar.style.width = '50%'; statusText.textContent = 'Creating professional PDF...'; // Create container with professional styling and margins const container = document.createElement('div'); container.innerHTML = result.value; container.style.cssText = ` position: fixed; left: -9999px; top: 0; width: 794px; background: white; z-index: -1; font-family: 'Calibri', Arial, sans-serif; font-size: 12pt; line-height: 1.6; padding: 60px 80px; color: #333; `; // Add professional styling to content const styleTag = document.createElement('style'); styleTag.textContent = ` body { margin: 0; padding: 0; } h1 { color: #1E40AF; font-size: 24pt; margin-bottom: 20px; } h2 { color: #1E40AF; font-size: 18pt; margin: 30px 0 15px 0; border-bottom: 2px solid #1E40AF; padding-bottom: 8px; } h3 { color: #3B82F6; font-size: 14pt; margin: 20px 0 10px 0; } p { margin-bottom: 12px; text-align: justify; } table { width: 100%; border-collapse: collapse; margin: 20px 0; } th, td { border: 1px solid #ccc; padding: 10px 12px; text-align: left; } th { background: #1E40AF; color: white; font-weight: bold; } tr:nth-child(even) { background: #f8fafc; } img { max-width: 100%; height: auto; margin: 20px 0; } ul, ol { margin: 10px 0 10px 30px; } li { margin-bottom: 5px; } `; container.appendChild(styleTag); document.body.appendChild(container); await new Promise(resolve => setTimeout(resolve, 500)); // Use html2canvas + jsPDF const { jsPDF } = window.jspdf; // A4 dimensions in mm const pageWidth = 210; const pageHeight = 297; const marginLeft = 20; const marginTop = 20; const marginRight = 20; const marginBottom = 20; const contentWidth = pageWidth - marginLeft - marginRight; const contentHeight = pageHeight - marginTop - marginBottom; const canvas = await html2canvas(container, { scale: 2, useCORS: true, logging: false, backgroundColor: '#ffffff' }); const imgData = canvas.toDataURL('image/jpeg', 0.95); const imgWidth = contentWidth; const imgHeight = canvas.height * imgWidth / canvas.width; const pdf = new jsPDF('p', 'mm', 'a4'); let heightLeft = imgHeight; let position = marginTop; // Add first page pdf.addImage(imgData, 'JPEG', marginLeft, position, imgWidth, imgHeight); heightLeft -= contentHeight; // Add additional pages while (heightLeft > 0) { position = heightLeft - imgHeight + marginTop; pdf.addPage(); pdf.addImage(imgData, 'JPEG', marginLeft, position, imgWidth, imgHeight); heightLeft -= contentHeight; } // Save PDF pdf.save(`${baseName}_converted.pdf`); // Clean up if (container.parentNode) { container.parentNode.removeChild(container); } progressBar.style.width = '100%'; } catch (error) { console.error('Word to PDF error:', error); const tempEls = document.querySelectorAll('[style*="left: -9999px"]'); tempEls.forEach(el => { if (el.parentNode) el.parentNode.removeChild(el); }); throw new Error('Word to PDF failed: ' + error.message); } } // 4. WORD TO PPT async function convertWordToPpt(baseName) { statusText.textContent = '📽️ Converting Word to PowerPoint...'; progressBar.style.width = '20%'; try { const arrayBuffer = await selectedFile.arrayBuffer(); const result = await mammoth.extractRawText({ arrayBuffer }); const paras = result.value.split('\n').filter(p => p.trim()); progressBar.style.width = '60%'; let pptx = new PptxGenJS(); pptx.layout = 'LAYOUT_16x9'; const titleSlide = pptx.addSlide(); titleSlide.background = { color: '1E40AF' }; titleSlide.addText(baseName, { x: 1, y: 1.5, w: 8, h: 1.5, fontSize: 32, bold: true, color: 'FFFFFF', align: 'center' }); titleSlide.addText('cmaknowledge.in', { x: 1, y: 3.5, w: 8, h: 0.5, fontSize: 16, color: 'BFDBFE', align: 'center' }); let slide = null; let yPos = 0.5; paras.forEach((p, idx) => { if (idx % 5 === 0) { slide = pptx.addSlide(); yPos = 0.5; } slide.addText(p.slice(0, 200), { x: 0.7, y: yPos, w: 8.6, h: 1.0, fontSize: 14, color: '333333' }); yPos += 1.1; }); const finalSlide = pptx.addSlide(); finalSlide.background = { color: '1E40AF' }; finalSlide.addText('Thank You!', { x: 1, y: 2, w: 8, h: 1, fontSize: 40, bold: true, color: 'FFFFFF', align: 'center' }); finalSlide.addText('Visit cmaknowledge.in', { x: 1, y: 3.5, w: 8, h: 0.5, fontSize: 16, color: 'BFDBFE', align: 'center' }); await pptx.writeFile({ fileName: `${baseName}_converted.pptx` }); progressBar.style.width = '100%'; } catch (error) { throw new Error('Word to PPT failed: ' + error.message); } } // 5. WORD TO EXCEL async function convertWordToExcel(baseName) { statusText.textContent = '📊 Converting Word to Excel...'; progressBar.style.width = '20%'; try { const arrayBuffer = await selectedFile.arrayBuffer(); const htmlResult = await mammoth.convertToHtml({ arrayBuffer }); progressBar.style.width = '40%'; const tempDiv = document.createElement('div'); tempDiv.innerHTML = htmlResult.value; const tables = tempDiv.querySelectorAll('table'); const wb = XLSX.utils.book_new(); if (tables.length > 0) { tables.forEach((table, index) => { const rows = []; table.querySelectorAll('tr').forEach(tr => { const row = []; tr.querySelectorAll('th, td').forEach(cell => { row.push(cell.textContent.trim()); }); if (row.length > 0) rows.push(row); }); if (rows.length > 0) { const ws = XLSX.utils.aoa_to_sheet(rows); XLSX.utils.book_append_sheet(wb, ws, `Table ${index + 1}`); } }); } const paragraphs = []; tempDiv.querySelectorAll('p, h1, h2, h3, h4').forEach(p => { const text = p.textContent.trim(); if (text) paragraphs.push([text]); }); if (paragraphs.length > 0) { const ws = XLSX.utils.aoa_to_sheet([['Content'], ...paragraphs]); ws['!cols'] = [{ wch: 80 }]; XLSX.utils.book_append_sheet(wb, ws, 'Text Content'); } progressBar.style.width = '80%'; if (wb.SheetNames.length === 0) { throw new Error('No content found'); } XLSX.writeFile(wb, `${baseName}_converted.xlsx`); progressBar.style.width = '100%'; } catch (error) { throw new Error('Word to Excel failed: ' + error.message); } } // 6. EXCEL TO WORD async function convertExcelToWord(baseName) { statusText.textContent = '📝 Converting Excel to Word...'; progressBar.style.width = '30%'; try { const arrayBuffer = await selectedFile.arrayBuffer(); const wb = XLSX.read(arrayBuffer, { type: 'array' }); progressBar.style.width = '50%'; let htmlContent = `${baseName}

${baseName}

Converted by cmaknowledge.in

`; wb.SheetNames.forEach(sheetName => { const ws = wb.Sheets[sheetName]; const data = XLSX.utils.sheet_to_json(ws, { header: 1 }); if (data.length > 0) { htmlContent += `

${sheetName}

`; data.forEach((row, rowIndex) => { htmlContent += ''; row.forEach(cell => { if (rowIndex === 0) { htmlContent += ``; } else { htmlContent += ``; } }); htmlContent += ''; }); htmlContent += '
${cell || ''}${cell || ''}
'; } }); htmlContent += `

Generated by CMA Knowledge Converter - cmaknowledge.in

`; progressBar.style.width = '80%'; downloadFile(['\ufeff', htmlContent], `${baseName}_converted.doc`, 'application/msword'); progressBar.style.width = '100%'; } catch (error) { throw new Error('Excel to Word failed: ' + error.message); } } function cancelConversion() { isProcessing = false; statusText.textContent = 'Conversion cancelled'; cancelBtn.classList.add('cma-hidden'); resetBtn.classList.remove('cma-hidden'); convertBtn.classList.remove('cma-hidden'); convertBtn.textContent = 'Convert Now'; } function resetConverter() { selectedFile = null; fileInput.value = ''; progressBar.style.width = '0%'; dropzone.classList.remove('cma-hidden'); processArea.style.display = 'none'; convertBtn.classList.remove('cma-hidden'); convertBtn.textContent = 'Convert Now'; cancelBtn.classList.add('cma-hidden'); resetBtn.classList.add('cma-hidden'); statusText.textContent = ''; } function formatFileSize(bytes) { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; } function downloadFile(content, fileName, mimeType) { const blob = content instanceof Blob ? content : new Blob([content], { type: mimeType }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = fileName; document.body.appendChild(a); a.click(); document.body.removeChild(a); setTimeout(() => URL.revokeObjectURL(url), 1000); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initConverter); } else { initConverter(); } })();

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
Scroll to Top
×