PNG to DOC Converter

Drag & Drop PNG Files Here

or click to browse files

Upload up to 20 PNG files at once

`; // Create blob with HTML content that can be opened as DOC const blob = new Blob([htmlContent], { type: 'application/msword' }); resolve(blob); } catch (error) { reject(new Error('Failed to create Word document: ' + error.message)); } }; img.onerror = () => { reject(new Error('Failed to load image')); }; img.src = e.target.result; } catch (error) { reject(new Error('Failed to process image: ' + error.message)); } }; reader.onerror = () => { reject(new Error('Failed to read file')); }; reader.readAsDataURL(file); }); } showProgress() { this.progressSection.style.display = 'block'; this.updateProgress(0, 'Starting conversion...'); } hideProgress() { this.progressSection.style.display = 'none'; } updateProgress(percentage, text) { this.progressFill.style.width = percentage + '%'; this.progressText.textContent = Math.round(percentage) + '%'; if (text) { const progressHeader = this.progressSection.querySelector('h3'); progressHeader.textContent = text; } } showResults() { this.resultsSection.style.display = 'block'; this.updateResultsList(); } hideResults() { this.resultsSection.style.display = 'none'; } updateResultsList() { const successCount = this.convertedFiles.filter(f => f.success).length; const totalCount = this.convertedFiles.length; const resultsHTML = this.convertedFiles.map(file => `
${file.originalName} → ${file.docName}
${file.success ? '
Converted successfully
' : `
Error: ${file.error}
` }
${file.success ? `` : '' }
`).join(''); this.fileResults.innerHTML = resultsHTML; // Update download all button if (successCount === 0) { this.downloadAllBtn.style.display = 'none'; } else { this.downloadAllBtn.style.display = 'inline-flex'; this.downloadAllBtn.innerHTML = ` Download ${successCount} DOC File${successCount > 1 ? 's' : ''} `; } } downloadSingleFile(index) { const file = this.convertedFiles[index]; if (file && file.success && file.blob) { this.downloadBlob(file.blob, file.docName); } } downloadAllFiles() { const successfulFiles = this.convertedFiles.filter(f => f.success); if (successfulFiles.length === 1) { // Download single file directly this.downloadBlob(successfulFiles[0].blob, successfulFiles[0].docName); } else if (successfulFiles.length > 1) { // Download multiple files with a small delay to avoid browser restrictions successfulFiles.forEach((file, index) => { setTimeout(() => { this.downloadBlob(file.blob, file.docName); }, index * 100); }); } } downloadBlob(blob, filename) { 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); URL.revokeObjectURL(url); } showError(message) { this.errorText.textContent = message; this.errorMessage.style.display = 'flex'; } hideError() { this.errorMessage.style.display = 'none'; } 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 when the page loads let converter; document.addEventListener('DOMContentLoaded', () => { converter = new PNGtoDOCConverter(); });// Prevent default drag behaviors on the document document.addEventListener('dragover', (e) => e.preventDefault()); document.addEventListener('drop', (e) => e.preventDefault());