I am trying to display all PDF stored on a folder. I have the following code that throws no error besides "Warning: TT: undefined function: 32 on util.js:373". In the DevTools I can see that the PDF document is found and loaded, and actualy the full website seems to be working fine, but a blank screen is showed on the brower where the PDF should be loaded.
The site loads first showPDF() function.
This is the showPDF() function:
function showPDFs() {
webFrame.src = 'about:blank';
pdfContainer.style.display = 'block';
// Obtener la lista de archivos PDF mediante AJAX
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
const pdfList = JSON.parse(xhr.responseText);
displayPDFs(pdfList, 0);
}
};
xhr.open('GET', 'get_pdf_list.php', true);
xhr.send();
}
and displayPDF() function:
function displayPDFs(pdfList, index) {
if (index >= pdfList.length) {
setTimeout(showWeb, pdfDisplayTime);
return;
}
const pdfUrl = pdfList[index];
// Cargar y mostrar el PDF en el visor de PDF.js
pdfContainer.innerHTML = '<canvas id="pdf-canvas"></canvas>';
const canvas = document.getElementById('pdf-canvas');
pdfjsLib.getDocument({ url: pdfUrl }).promise.then(function (pdfDoc) {
pdfDoc.getPage(1).then(function (page) {
const viewport = page.getViewport({ scale: 1.5 });
canvas.height = viewport.height;
canvas.width = viewport.width;
const context = canvas.getContext('2d');
page.render({
canvasContext: context,
viewport: viewport
}).promise.then(function () {
setTimeout(() => {
displayPDFs(pdfList, index + 1);
}, pdfDisplayTime);
});
});
});
}
This is the get_pdf_list.php code:
<?php
$dir = 'files/BRKROOM01/';
$files = array_diff(scandir($dir), array('..', '.'));
$pdfList = [];
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) == 'pdf') {
$pdfList[] = $dir . $file;
}
}
echo json_encode($pdfList);
?>
I can't see anything wrong, and as mentioned, everything seems to be running but no PDF displayed. I tried changing the code a thousand times, but nothing works.