PDF-Export: Autotable-Plugin zuverlaessig laden vor der Generierung

loadPdfLibraries() hat im "bereits ladend"-Zweig aufgeloest, sobald jsPDF
vorhanden war — das Autotable-Plugin (zweites Script) war dann aber noch
nicht angehaengt, sodass doc.autoTable undefined war und die Generierung
mit "doc.autoTable is not a function" fehlschlug. Die Polling-Bedingung
prueft jetzt auch jsPDF.API.autoTable, und generatePDF wartet zusaetzlich
auf loadPdfLibraries(), bevor das Dokument gebaut wird.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-14 02:35:37 +02:00
co-authored by Claude
parent 167960b91a
commit 69e6a29d87
+13 -2
View File
@@ -212,11 +212,17 @@ function generatePDF(event) {
url += params.join('&') + '&';
}
// loadPdfLibraries() is awaited here too (not only when the modal opens) so
// the autotable plugin is guaranteed to be attached before we build the doc.
// Without this, opening the modal and submitting before the plugin script
// finished loading would reach generatePdfDocument() with doc.autoTable
// still undefined ("doc.autoTable is not a function").
Promise.all([
loadPdfLibraries(),
fetch('/api/settings').then(res => res.json()),
fetch(url).then(res => res.json())
])
.then(([settings, applications]) => {
.then(([_loaded, settings, applications]) => {
generatePdfDocument(settings, applications, month, year);
hideModal(pdfExportModal);
})
@@ -603,7 +609,12 @@ function loadPdfLibraries() {
// Check if already loading
if (document.getElementById('jspdf-script')) {
const checkLoaded = setInterval(() => {
if (window.jspdf && window.jspdf.jsPDF) {
// Wait for the autotable plugin too, not just jsPDF: jsPDF loads
// first (script1), the plugin second (script2). Resolving the
// moment jsPDF exists leaves doc.autoTable undefined if script2
// has not run yet.
if (window.jspdf && window.jspdf.jsPDF
&& typeof window.jspdf.jsPDF.API.autoTable === 'function') {
clearInterval(checkLoaded);
pdfLibrariesLoaded = true;
resolve();