PDF to Image Converter

`; previewContainer.appendChild(previewImage); } downloadZipLink.style.display = 'inline-block'; downloadZipLink.download = `${pdfFileName}_ YusufRecords.zip`; }; loadingSpinner.style.display = 'none'; reader.readAsArrayBuffer(file); } else { alert('Please select a PDF file.'); } } function downloadImage(fileName, dataUrl) { const link = document.createElement('a'); link.href = dataUrl; link.download = fileName; link.target = '_blank'; link.style.display = 'none'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } function downloadZip() { const zip = new JSZip(); const previewContainer = document.getElementById('previewContainer').getElementsByTagName('img'); const loadingSpinner = document.getElementById('loadingSpinner'); // Extract PDF file name without extension const pdfFileName = pdfInput.files[0].name.replace(/\.[^/.]+$/, ""); loadingSpinner.style.display = 'inline-block'; // Use Promise.all to wait for all images to be added to the zip Promise.all(Array.from(previewContainer).map((img, i) => { const imageSrc = img.src; return fetch(imageSrc).then(response => response.blob()).then(blob => { zip.file(`${pdfFileName}_page_${i + 1}.jpg`, blob); }); })).then(() => { // Generate the zip file zip.generateAsync({ type: 'blob' }) .then(function (content) { // Trigger the download const zipFileName = `${pdfFileName}_ YusufRecords.zip`; saveAs(content, zipFileName); loadingSpinner.style.display = 'none'; }); }); } function dataURItoBlob(dataURI) { const byteString = atob(dataURI); const ab = new ArrayBuffer(byteString.length); const ia = new Uint8Array(ab); for (let i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } return new Blob([ab], { type: 'image/jpeg' }); }