update
This commit is contained in:
@@ -77,6 +77,7 @@ import { useNotification } from '../contexts/NotificationContext';
|
||||
import { trainingApi } from '../services/training';
|
||||
import { eventsApi } from '../services/events';
|
||||
import { configApi, type PdfSettings } from '../services/config';
|
||||
import { addPdfHeader, addPdfFooter } from '../utils/pdfExport';
|
||||
import type {
|
||||
UebungListItem,
|
||||
UebungTyp,
|
||||
@@ -608,49 +609,6 @@ function DayPopover({
|
||||
);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────────
|
||||
// PDF Export helper
|
||||
// ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Render text with basic markdown (**bold**) and line breaks into a jsPDF doc.
|
||||
* Returns the final Y position after rendering.
|
||||
*/
|
||||
function renderMarkdownText(
|
||||
doc: import('jspdf').jsPDF,
|
||||
text: string,
|
||||
x: number,
|
||||
y: number,
|
||||
options?: { fontSize?: number; maxWidth?: number },
|
||||
): number {
|
||||
const fontSize = options?.fontSize ?? 9;
|
||||
const lineHeight = fontSize * 0.5; // ~mm per line
|
||||
doc.setFontSize(fontSize);
|
||||
doc.setTextColor(0, 0, 0);
|
||||
|
||||
const lines = text.split('\n');
|
||||
let curY = y;
|
||||
|
||||
for (const line of lines) {
|
||||
// Split by ** to alternate normal/bold
|
||||
const segments = line.split('**');
|
||||
let curX = x;
|
||||
for (let i = 0; i < segments.length; i++) {
|
||||
const seg = segments[i];
|
||||
if (!seg) continue;
|
||||
const isBold = i % 2 === 1;
|
||||
doc.setFont('helvetica', isBold ? 'bold' : 'normal');
|
||||
doc.text(seg, curX, curY);
|
||||
curX += doc.getTextWidth(seg);
|
||||
}
|
||||
curY += lineHeight;
|
||||
}
|
||||
|
||||
// Reset font
|
||||
doc.setFont('helvetica', 'normal');
|
||||
return curY;
|
||||
}
|
||||
|
||||
let _pdfSettingsCache: PdfSettings | null = null;
|
||||
let _pdfSettingsCacheTime = 0;
|
||||
|
||||
@@ -683,41 +641,8 @@ async function generatePdf(
|
||||
|
||||
const pdfSettings = await fetchPdfSettings();
|
||||
|
||||
// Header bar
|
||||
doc.setFillColor(183, 28, 28); // fire-red
|
||||
doc.rect(0, 0, 297, 18, 'F');
|
||||
doc.setTextColor(255, 255, 255);
|
||||
doc.setFontSize(14);
|
||||
doc.setFont('helvetica', 'bold');
|
||||
doc.text(`Kalender — ${monthLabel} ${year}`, 10, 12);
|
||||
|
||||
// Right side: logo and/or org name
|
||||
const logoSize = 14;
|
||||
const logoX = 297 - 4 - logoSize; // 4mm right margin
|
||||
if (pdfSettings.pdf_logo) {
|
||||
try {
|
||||
const fmt = pdfSettings.pdf_logo.match(/^data:image\/(\w+);/)?.[1]?.toUpperCase() ?? 'PNG';
|
||||
doc.addImage(pdfSettings.pdf_logo, fmt === 'JPG' ? 'JPEG' : fmt, logoX, 2, logoSize, logoSize);
|
||||
} catch { /* ignore invalid image */ }
|
||||
}
|
||||
if (pdfSettings.pdf_org_name) {
|
||||
doc.setFontSize(9);
|
||||
doc.setFont('helvetica', 'bold');
|
||||
doc.setTextColor(255, 255, 255);
|
||||
const nameW = doc.getTextWidth(pdfSettings.pdf_org_name);
|
||||
const nameX = (pdfSettings.pdf_logo ? logoX - 3 : 297 - 4) - nameW;
|
||||
doc.text(pdfSettings.pdf_org_name, nameX, 12);
|
||||
} else if (!pdfSettings.pdf_logo) {
|
||||
doc.setFontSize(9);
|
||||
doc.setFont('helvetica', 'normal');
|
||||
doc.text('Feuerwehr Rems', 250, 12);
|
||||
}
|
||||
|
||||
// Custom header text
|
||||
let tableStartY = 22;
|
||||
if (pdfSettings.pdf_header) {
|
||||
tableStartY = renderMarkdownText(doc, pdfSettings.pdf_header, 10, 24, { fontSize: 9 }) + 2;
|
||||
}
|
||||
// Header
|
||||
const tableStartY = addPdfHeader(doc, `Kalender — ${monthLabel} ${year}`, pdfSettings, 297);
|
||||
|
||||
// Build combined list (same logic as CombinedListView)
|
||||
type ListEntry =
|
||||
@@ -766,11 +691,7 @@ async function generatePdf(
|
||||
3: { cellWidth: 40 },
|
||||
4: { cellWidth: 60 },
|
||||
},
|
||||
didDrawPage: pdfSettings.pdf_footer
|
||||
? () => {
|
||||
renderMarkdownText(doc, pdfSettings.pdf_footer, 10, doc.internal.pageSize.height - 12, { fontSize: 8 });
|
||||
}
|
||||
: undefined,
|
||||
didDrawPage: addPdfFooter(doc, pdfSettings),
|
||||
});
|
||||
|
||||
const filename = `kalender_${year}_${String(month + 1).padStart(2, '0')}.pdf`;
|
||||
|
||||
Reference in New Issue
Block a user