X

Free Online PDF to Word Converter to Convert PDF into Editable DOCX

Convert PDF files to editable Word documents online with our free PDF to Word Converter. Fast, secure, accurate, and no registration required.






Premium PDF to Word Converter | WordPress Tool


Convert your PDF documents to editable Word files instantly. No registration required. Preserves formatting and works on all devices.

Upload PDF

Drag & Drop Your PDF Here

or click to browse files


Please select a valid PDF file (max 10MB).

Selected File:

document.pdf
2.4 MB

Conversion Options

Output Format


Content Extraction




Document Settings



Initializing PDF conversion…

Conversion Progress

0%

Extracted Text Preview

Conversion Successful!

Your PDF has been converted to Word format. Click the button below to download your file.

Want to convert another file? Click here

Secure & Private

Your documents are processed locally in your browser. We never upload your files to any server.

Mobile Friendly

Works perfectly on all devices – smartphones, tablets, and desktop computers.

Fast Conversion

Convert PDF to Word in seconds using advanced browser-based conversion technology.

Preserves Formatting

Maintains original layout, fonts, and structure for accurate document conversion.

© 2023 Premium PDF to Word Converter. This tool works entirely in your browser for maximum privacy.

Powered by PDF.js and Docx.js libraries. For support, contact your website administrator.

// State variables let selectedFile = null; let pdfDocument = null; let extractedText = ''; let convertedDoc = null;

// Event Listeners browseBtn.addEventListener('click', () => fileInput.click());

fileInput.addEventListener('change', (e) => { if (e.target.files.length > 0) { handleFileSelection(e.target.files[0]); } });

// Drag and drop functionality dropZone.addEventListener('dragover', (e) => { e.preventDefault(); dropZone.classList.add('dragover'); });

dropZone.addEventListener('dragleave', () => { dropZone.classList.remove('dragover'); });

dropZone.addEventListener('drop', (e) => { e.preventDefault(); dropZone.classList.remove('dragover');

if (e.dataTransfer.files.length > 0) { handleFileSelection(e.dataTransfer.files[0]); } });

// Convert button click convertBtn.addEventListener('click', convertFile);

// Download button click downloadBtn.addEventListener('click', downloadDocument);

// Convert another file convertAnother.addEventListener('click', resetConverter);

// Close preview closePreview.addEventListener('click', () => { previewArea.classList.remove('active'); });

// Handle file selection function handleFileSelection(file) { // Validate file type if (!file.type.includes('pdf') && !file.name.toLowerCase().endsWith('.pdf')) { showError('Please select a valid PDF file.'); return; }

// Validate file size (max 10MB) if (file.size > 10 * 1024 * 1024) { showError('File size exceeds 10MB limit. Please select a smaller file.'); return; }

// Hide any previous error hideError();

// Store file and update UI selectedFile = file;

// Update file info display fileName.textContent = file.name; fileSize.textContent = formatFileSize(file.size); fileInfo.classList.add('active');

// Enable convert button convertBtn.disabled = false; }

// Convert file function async function convertFile() { if (!selectedFile) { showError('Please select a PDF file first.'); return; }

try { // Show loading state loading.classList.add('active'); conversionProgress.classList.add('active'); loadingText.textContent = 'Loading PDF document...'; convertBtn.disabled = true;

// Update progress updateProgress(10);

// Load the PDF file const arrayBuffer = await selectedFile.arrayBuffer();

// Initialize PDF.js pdfjsLib.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js`;

// Load the PDF document loadingText.textContent = 'Parsing PDF document...'; updateProgress(20);

pdfDocument = await pdfjsLib.getDocument({ data: arrayBuffer }).promise; const numPages = pdfDocument.numPages;

// Extract text from each page loadingText.textContent = `Extracting text from ${numPages} pages...`; updateProgress(30);

extractedText = ''; let extractedPages = 0;

for (let pageNum = 1; pageNum item.str) .join(' ');

extractedText += pageText;

// Add page break if not last page if (pageNum p.trim().length > 0);

// Create document paragraphs const docParagraphs = [];

// Add title const title = originalFileName.replace('.pdf', '').replace('.PDF', ''); docParagraphs.push( new Paragraph({ text: title, heading: HeadingLevel.HEADING_1, alignment: AlignmentType.CENTER, spacing: { after: 400 } }) );

// Process each paragraph paragraphs.forEach(paragraph => { // Check if this is a page separator if (paragraph.includes('--- Page')) { if (includePageNumbers) { const pageNum = paragraph.match(/Page (\d+)/)[1]; docParagraphs.push( new Paragraph({ text: `Page ${pageNum}`, heading: HeadingLevel.HEADING_3, alignment: AlignmentType.CENTER, spacing: { before: 300, after: 200 } }) ); } } else { // Regular paragraph docParagraphs.push( new Paragraph({ children: [ new TextRun({ text: paragraph, size: fontSize * 2, // Docx uses half-points (24 = 12pt) font: fontFamily }) ], spacing: { after: 200 } }) ); } });

// Create document const doc = new Document({ sections: [{ properties: {}, children: docParagraphs }] });

return doc; }

// Download the converted document async function downloadDocument() { if (!convertedDoc) { showError('No document to download. Please convert a file first.'); return; }

try { const { Packer } = docx;

// Generate blob const blob = await Packer.toBlob(convertedDoc);

// Create download link const fileName = selectedFile.name.replace('.pdf', '').replace('.PDF', '') + '_converted.docx';

// Save file saveAs(blob, fileName);

} catch (error) { console.error('Download error:', error); showError('Failed to generate download. Please try again.'); } }

// Show preview of extracted text function showPreview(text) { // Limit preview to 1000 characters const previewText = text.length > 1000 ? text.substring(0, 1000) + '...' : text;

// Format preview with line breaks const formattedPreview = previewText .replace(/\n/g, '
') .replace(/ /g, '  ');

previewContent.innerHTML = formattedPreview; previewArea.classList.add('active'); }

// Reset converter to initial state function resetConverter() { selectedFile = null; pdfDocument = null; extractedText = ''; convertedDoc = null;

fileInput.value = ''; fileInfo.classList.remove('active'); convertBtn.disabled = true; resultArea.classList.remove('active'); previewArea.classList.remove('active'); conversionProgress.classList.remove('active'); hideError();

// Reset progress bar updateProgress(0);

// Scroll to top document.querySelector('.upload-area').scrollIntoView({ behavior: 'smooth' }); }

// Update progress bar function updateProgress(percentage) { progressFill.style.width = `${percentage}%`; progressText.textContent = `${Math.round(percentage)}%`; }

// Show error message function showError(message) { errorText.textContent = message; errorAlert.style.display = 'block'; errorAlert.classList.remove('success', 'info'); errorAlert.classList.add('error'); }

// Hide error message function hideError() { errorAlert.style.display = 'none'; }

// Format file size 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]; }

// Initialize the converter function initConverter() { // Hide error on load hideError();

// Set PDF.js worker if (pdfjsLib) { pdfjsLib.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js`; }

console.log('PDF to Word Converter initialized with PDF.js and Docx.js integration.'); }

// Initialize when page loads document.addEventListener('DOMContentLoaded', initConverter);

admin:
Leave a Comment

This website uses cookies.