PDF to word and vice-versa PDF to word & words to PdfOnline tool

PDF ⇄ Word | Pro Converter

PDFWord

Professional converter · mobile ready
`; const blob = new Blob([wordHTML], { type: 'application/msword' }); // .doc mime const url = URL.createObjectURL(blob); const originalName = file.name.replace(/\.pdf$/i, '') || 'converted'; triggerDownload(url, `${originalName}_converted.doc`); showStatus('PDF → Word completed! (text extracted)', false); }// Word to PDF: use mammoth to convert docx to HTML, then html2canvas + jspdf async function convertWordToPdf(file) { if (typeof mammoth === 'undefined') { throw new Error('Mammoth library not loaded.'); }const arrayBuffer = await readFileAsArrayBuffer(file); const result = await mammoth.convertToHtml({ arrayBuffer: arrayBuffer }); const htmlContent = result.value;// Create temporary container to render HTML and capture as PDF const container = document.createElement('div'); container.style.position = 'absolute'; container.style.left = '-9999px'; container.style.top = '0'; container.style.width = '800px'; container.style.padding = '40px'; container.style.background = 'white'; container.style.color = 'black'; container.style.fontFamily = 'Arial, sans-serif'; container.innerHTML = htmlContent; document.body.appendChild(container);try { // Use html2canvas to capture const canvas = await html2canvas(container, { scale: 2, useCORS: true, logging: false, backgroundColor: '#ffffff' });const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: canvas.width > canvas.height ? 'landscape' : 'portrait', unit: 'px', format: [canvas.width, canvas.height] });pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height, undefined, 'FAST'); const pdfBlob = pdf.output('blob'); const url = URL.createObjectURL(pdfBlob); const originalName = file.name.replace(/\.(docx|doc)$/i, '') || 'document'; triggerDownload(url, `${originalName}_converted.pdf`); showStatus('Word → PDF completed!', false); } finally { document.body.removeChild(container); } }function triggerDownload(url, filename) { downloadLink.href = url; downloadLink.download = filename; downloadLink.classList.remove('hidden'); outputContainer.classList.remove('hidden'); statusMessage.textContent = '✅ File ready!'; // Auto click not always allowed on mobile, but link visible. }function readFileAsArrayBuffer(file) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result); reader.onerror = reject; reader.readAsArrayBuffer(file); }); }function loadScript(url) { return new Promise((resolve, reject) => { if (document.querySelector(`script[src="${url}"]`)) return resolve(); const script = document.createElement('script'); script.src = url; script.onload = resolve; script.onerror = () => reject(new Error(`Failed to load ${url}`)); document.head.appendChild(script); }); }// Reset button resetBtn.addEventListener('click', () => { clearFileSelection(); // Keep mode but clear everything hideOutput(); fileNameDisplay.textContent = ''; });// Mode switch listeners pdfToWordBtn.addEventListener('click', () => setMode('pdfToWord')); wordToPdfBtn.addEventListener('click', () => setMode('wordToPdf'));// Initialize with PDF to Word mode active setMode('pdfToWord'); })();