`;
htmlEditor.value = currentHtml;
updateHtmlPreview();
progressBar.style.width = '100%';
progressText.textContent = 'Webpage fetched successfully!';
fetchBtn.disabled = false;
previewContainer.style.display = 'flex';
}, 1500);
}, 500);
}
function updateHtmlPreview() {
if (!currentHtml) return;
htmlPreview.srcdoc = currentHtml;
htmlPreview.style.display = 'block';
htmlPlaceholder.style.display = 'none';
}
function convertToPdf() {
if (!currentHtml && !htmlEditor.value) {
alert('Please fetch a webpage or enter HTML code first');
return;
}
const htmlContent = htmlEditor.value || currentHtml;
progressContainer.style.display = 'block';
progressBar.style.width = '0%';
progressText.textContent = 'Converting to PDF...';
convertBtn.disabled = true;
// In a real app, you would use a PDF generation library
// This is a simulated conversion for demo purposes
setTimeout(() => {
progressBar.style.width = '50%';
progressText.textContent = 'Processing content...';
setTimeout(() => {
progressBar.style.width = '90%';
progressText.textContent = 'Generating PDF...';
const dummyPdf = `
This is a simulated PDF generated from your HTML content.
Page 1
In a real implementation, the PDF would contain the actual converted content.
Page 2
With all the formatting preserved according to your settings.
`;
pdfPreview.srcdoc = dummyPdf;
pdfPreview.style.display = 'block';
pdfPlaceholder.style.display = 'none';
// Create a downloadable PDF (simulated)
pdfUrl = URL.createObjectURL(new Blob([dummyPdf], { type: 'text/html' }));
progressBar.style.width = '100%';
progressText.textContent = 'Conversion complete!';
downloadBtn.disabled = false;
convertBtn.disabled = false;
}, 1500);
}, 1000);
}
function downloadPdf() {
if (!pdfUrl) return;
const a = document.createElement('a');
a.href = pdfUrl;
a.download = 'converted-document.pdf';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function resetTool() {
urlInput.value = '';
htmlEditor.value = '';
currentHtml = '';
pdfUrl = null;
previewContainer.style.display = 'none';
htmlPreview.src = '';
htmlPreview.style.display = 'none';
htmlPlaceholder.style.display = 'flex';
pdfPreview.src = '';
pdfPreview.style.display = 'none';
pdfPlaceholder.style.display = 'flex';
downloadBtn.disabled = true;
progressContainer.style.display = 'none';
convertBtn.disabled = false;
fetchBtn.disabled = false;
// Reset options to defaults
includeBackgrounds.checked = true;
enableJavaScript.checked = false;
loadImages.checked = true;
pageSize.value = 'A4';
marginSize.value = '10';
zoomLevel.value = '100';
zoomLevelValue.textContent = '100%';
// Reset to URL tab
switchTab('url');
}
});