| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Enhanced DOCX to PDF Converter</title> |
| <style> |
| body { |
| font-family: Arial, sans-serif; |
| max-width: 800px; |
| margin: 0 auto; |
| padding: 20px; |
| background-color: #f5f5f5; |
| } |
| .container { |
| background-color: white; |
| padding: 30px; |
| border-radius: 10px; |
| box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
| } |
| h1 { |
| color: #333; |
| text-align: center; |
| } |
| .form-group { |
| margin-bottom: 20px; |
| } |
| label { |
| display: block; |
| margin-bottom: 5px; |
| font-weight: bold; |
| } |
| input[type="file"] { |
| width: 100%; |
| padding: 10px; |
| border: 1px solid #ddd; |
| border-radius: 5px; |
| } |
| button { |
| background-color: #007bff; |
| color: white; |
| padding: 12px 24px; |
| border: none; |
| border-radius: 5px; |
| cursor: pointer; |
| font-size: 16px; |
| width: 100%; |
| } |
| button:hover { |
| background-color: #0056b3; |
| } |
| button:disabled { |
| background-color: #ccc; |
| cursor: not-allowed; |
| } |
| .result { |
| margin-top: 20px; |
| padding: 15px; |
| border-radius: 5px; |
| display: none; |
| } |
| .success { |
| background-color: #d4edda; |
| color: #155724; |
| border: 1px solid #c3e6cb; |
| } |
| .error { |
| background-color: #f8d7da; |
| color: #721c24; |
| border: 1px solid #f5c6cb; |
| } |
| .loading { |
| text-align: center; |
| display: none; |
| } |
| .spinner { |
| border: 4px solid #f3f3f3; |
| border-top: 4px solid #3498db; |
| border-radius: 50%; |
| width: 30px; |
| height: 30px; |
| animation: spin 1s linear infinite; |
| margin: 0 auto 10px; |
| } |
| @keyframes spin { |
| 0% { transform: rotate(0deg); } |
| 100% { transform: rotate(360deg); } |
| } |
| </style> |
| </head> |
| <body> |
| <div class="container"> |
| <h1>Enhanced DOCX to PDF Converter</h1> |
| <form id="convertForm"> |
| <div class="form-group"> |
| <label for="docxFile">Select DOCX File:</label> |
| <input type="file" id="docxFile" accept=".docx" required> |
| </div> |
| <button type="submit" id="convertBtn">Convert to PDF</button> |
| </form> |
| |
| <div class="loading" id="loading"> |
| <div class="spinner"></div> |
| <p>Converting your document...</p> |
| </div> |
| |
| <div class="result success" id="successResult"> |
| <h3>Conversion Successful!</h3> |
| <p>Your PDF has been generated successfully.</p> |
| <a id="downloadLink" href="#" target="_blank">Download PDF</a> |
| </div> |
| |
| <div class="result error" id="errorResult"> |
| <h3>Conversion Failed</h3> |
| <p id="errorMessage"></p> |
| </div> |
| </div> |
|
|
| <script> |
| document.getElementById('convertForm').addEventListener('submit', async function(e) { |
| e.preventDefault(); |
| |
| const fileInput = document.getElementById('docxFile'); |
| const convertBtn = document.getElementById('convertBtn'); |
| const loading = document.getElementById('loading'); |
| const successResult = document.getElementById('successResult'); |
| const errorResult = document.getElementById('errorResult'); |
| const errorMessage = document.getElementById('errorMessage'); |
| const downloadLink = document.getElementById('downloadLink'); |
| |
| |
| successResult.style.display = 'none'; |
| errorResult.style.display = 'none'; |
| |
| if (!fileInput.files.length) { |
| showError('Please select a file'); |
| return; |
| } |
| |
| const file = fileInput.files[0]; |
| if (!file.name.endsWith('.docx')) { |
| showError('Please select a DOCX file'); |
| return; |
| } |
| |
| |
| convertBtn.disabled = true; |
| loading.style.display = 'block'; |
| |
| try { |
| const formData = new FormData(); |
| formData.append('file', file); |
| |
| const response = await fetch('http://localhost:8000/convert', { |
| method: 'POST', |
| body: formData |
| }); |
| |
| const result = await response.json(); |
| |
| if (result.success) { |
| |
| loading.style.display = 'none'; |
| successResult.style.display = 'block'; |
| downloadLink.href = 'http://localhost:8000' + result.pdf_url; |
| } else { |
| throw new Error(result.error || 'Conversion failed'); |
| } |
| } catch (error) { |
| showError(error.message || 'An error occurred during conversion'); |
| } finally { |
| convertBtn.disabled = false; |
| loading.style.display = 'none'; |
| } |
| }); |
| |
| function showError(message) { |
| document.getElementById('loading').style.display = 'none'; |
| document.getElementById('errorResult').style.display = 'block'; |
| document.getElementById('errorMessage').textContent = message; |
| } |
| </script> |
| </body> |
| </html> |