File size: 5,948 Bytes
623e14e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | <!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');
// Reset UI
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;
}
// Show loading
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) {
// Show 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> |