diff --git a/frontend/src/components/PDFGenerator.js b/frontend/src/components/PDFGenerator.js index 999ae3a..b79338b 100644 --- a/frontend/src/components/PDFGenerator.js +++ b/frontend/src/components/PDFGenerator.js @@ -243,37 +243,69 @@ class PDFGenerator { addTable(tableId, highlightName = '', excludeColumns = []) { this.pdf.setFontSize(11); - autoTable(this.pdf, { - html: `#${tableId}`, - startY: this.cursorY, - margin: { left: this.margin, right: this.margin }, - styles: { fontSize: this.pdf.getFontSize() }, - headStyles: { fillColor: [220, 220, 220], textColor: 0, halign: 'left' }, - theme: 'grid', - didParseCell: (data) => { - // Spalten ausschließen - if (excludeColumns.includes(data.column.index)) { - data.cell.styles.display = 'none'; - return; + + // Wenn Spalten ausgeschlossen werden sollen, parse die Tabelle manuell + if (excludeColumns.length > 0) { + const table = document.querySelector(`#${tableId}`); + if (!table) return; + + const headers = Array.from(table.querySelectorAll('thead th')) + .map((th, index) => ({ text: th.textContent.trim(), index })) + .filter(h => !excludeColumns.includes(h.index)) + .map(h => h.text); + + const rows = Array.from(table.querySelectorAll('tbody tr')).map(tr => { + return Array.from(tr.querySelectorAll('td')) + .map((td, index) => ({ text: td.textContent.trim(), index })) + .filter(cell => !excludeColumns.includes(cell.index)) + .map(cell => cell.text); + }); + + autoTable(this.pdf, { + head: [headers], + body: rows, + startY: this.cursorY, + margin: { left: this.margin, right: this.margin }, + styles: { fontSize: this.pdf.getFontSize(), cellPadding: 3, overflow: 'linebreak' }, + headStyles: { fillColor: [220, 220, 220], textColor: 0, halign: 'left', fontStyle: 'bold' }, + theme: 'grid', + tableWidth: 'auto', + didParseCell: (data) => { + if (data.section === 'body') { + const cellText = Array.isArray(data.cell.text) + ? data.cell.text.join(' ') + : String(data.cell.text); + if (highlightName && cellText.includes(highlightName)) { + data.cell.styles.fontStyle = 'bold'; + } + } + }, + didDrawPage: (data) => { + this.cursorY = data.cursor.y + 10; } - - const cellText = Array.isArray(data.cell.text) - ? data.cell.text.join(' ') - : String(data.cell.text); - if (highlightName && cellText.includes(highlightName)) { - data.cell.styles.fontStyle = 'bold'; + }); + } else { + // Ohne Ausschluss: normale HTML-Tabelle verwenden + autoTable(this.pdf, { + html: `#${tableId}`, + startY: this.cursorY, + margin: { left: this.margin, right: this.margin }, + styles: { fontSize: this.pdf.getFontSize() }, + headStyles: { fillColor: [220, 220, 220], textColor: 0, halign: 'left' }, + theme: 'grid', + didParseCell: (data) => { + const cellText = Array.isArray(data.cell.text) + ? data.cell.text.join(' ') + : String(data.cell.text); + if (highlightName && cellText.includes(highlightName)) { + data.cell.styles.fontStyle = 'bold'; + } + }, + didDrawPage: (data) => { + this.cursorY = data.cursor.y + 10; } - }, - didDrawPage: (data) => { - this.cursorY = data.cursor.y + 10; - }, - // Spalten aus dem Header entfernen - willDrawCell: (data) => { - if (excludeColumns.includes(data.column.index)) { - return false; - } - } - }); + }); + } } addParticipantsSummary(tournamentTitle, tournamentDateText, groups) {