//Utils.js - general utilities function returnNumberfromString(str) { var tmpstr=str; if(tmpstr!=undefined) { if(tmpstr.length>0) { tmpstr = tmpstr.replace(/\D/g,''); } } return Number(tmpstr); } function removeallnonnumbersfromstring(txt) { var num = txt.replace(/[^0-9]/g, ''); var res=Number(num); return res; } async function checkFileExists(url) { try { const response = await fetch(url, { method: 'HEAD' }); return response.ok; } catch (error) { console.error('Error checking file existence:', error); return false; } } /* // Usage example const fileUrl = 'https://example.com/file.pdf'; checkFileExists(fileUrl).then(exists => { if (!exists){ alert('no exist') }}); */ async function downloadPDFasDataURL(url) { try { // Fetch the PDF file from the URL const response = await fetch(url); // Check if the response is OK if (!response.ok) { throw new Error('Network response was not ok'); } // Convert the response to a Blob const blob = await response.blob(); // Create a FileReader to read the Blob as a data URL const reader = new FileReader(); reader.readAsDataURL(blob); // Return a promise that resolves with the data URL return new Promise((resolve, reject) => { reader.onloadend = () => resolve(reader.result); reader.onerror = reject; }); } catch (error) { console.error('Error downloading PDF:', error); } } /* // Example usage downloadPDF('https://example.com/sample.pdf').then(dataURL => { console.log('PDF as data URL:', dataURL); }); */