var pdfRenderTasks = []; var pdfPages = []; var windowWidth = window.innerWidth; var is_mobile = function() { return !(window.getComputedStyle(document.getElementById('is_mobile')).display === "none"); }; var nbPagePerLine = 5; if(is_mobile()) { nbPagePerLine = 2; } var loadPDF = async function(pdfBlob, filename) { var pdfjsLib = window['pdfjs-dist/build/pdf']; pdfjsLib.GlobalWorkerOptions.workerSrc = '/vendor/pdf.worker.js?legacy'; let url = await URL.createObjectURL(pdfBlob); let dataTransfer = new DataTransfer(); dataTransfer.items.add(new File([pdfBlob], filename, { type: 'application/pdf' })); document.getElementById('input_pdf').files = dataTransfer.files; var loadingTask = pdfjsLib.getDocument(url); loadingTask.promise.then(function(pdf) { for(var pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { pdf.getPage(pageNumber).then(function(page) { let viewport = page.getViewport({scale: 1}); let scale = (document.getElementById('container-pages').clientWidth - (8*nbPagePerLine) - 12) / viewport.width / nbPagePerLine; viewport = page.getViewport({scale: scale}); var pageIndex = page.pageNumber - 1; document.getElementById('container-pages').insertAdjacentHTML('beforeend', '
Page '+page.pageNumber+' - '+filename+'