chore: add verbose browser console logs for PDF export diagnostics
This commit is contained in:
@@ -498,15 +498,25 @@ function closeAiModal(){
|
||||
}
|
||||
|
||||
async function downloadPdf(){
|
||||
console.log('[PDF] click');
|
||||
const openPrintFallback = (msg='') => {
|
||||
console.warn('[PDF] fallback print', msg || '(no message)');
|
||||
if (msg) alert(msg);
|
||||
const w = window.open('', '_blank');
|
||||
if (!w) return;
|
||||
if (!w) {
|
||||
console.error('[PDF] fallback window blocked');
|
||||
return;
|
||||
}
|
||||
w.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title></head><body>${app.innerHTML}</body></html>`);
|
||||
w.document.close();
|
||||
w.onload = () => setTimeout(() => w.print(), 200);
|
||||
};
|
||||
|
||||
console.log('[PDF] libs', {
|
||||
html2canvas: !!window.html2canvas,
|
||||
jspdf: !!(window.jspdf && window.jspdf.jsPDF)
|
||||
});
|
||||
|
||||
if (!window.html2canvas || !window.jspdf?.jsPDF) {
|
||||
openPrintFallback('PDF-Bibliotheken fehlen – Druckdialog als Fallback.');
|
||||
return;
|
||||
@@ -525,6 +535,7 @@ async function downloadPdf(){
|
||||
|
||||
try {
|
||||
const cards = [...root.querySelectorAll('.card-size')];
|
||||
console.log('[PDF] cards found', cards.length);
|
||||
if (!cards.length) throw new Error('Keine Karten sichtbar');
|
||||
|
||||
const { jsPDF } = window.jspdf;
|
||||
@@ -536,6 +547,7 @@ async function downloadPdf(){
|
||||
const usableH = pageH - margin * 2;
|
||||
|
||||
for (let i = 0; i < cards.length; i++) {
|
||||
console.log('[PDF] rendering card', i + 1, '/', cards.length);
|
||||
const canvas = await Promise.race([
|
||||
window.html2canvas(cards[i], { scale: 2, useCORS: true, backgroundColor: '#ffffff', logging: false }),
|
||||
new Promise((_, rej) => setTimeout(() => rej(new Error('Render timeout')), 15000))
|
||||
@@ -550,16 +562,19 @@ async function downloadPdf(){
|
||||
pdf.addImage(img, 'JPEG', x, y, drawW, drawH, undefined, 'FAST');
|
||||
}
|
||||
|
||||
pdf.save(`coachingcards-${new Date().toISOString().slice(0,10)}.pdf`);
|
||||
const filename = `coachingcards-${new Date().toISOString().slice(0,10)}.pdf`;
|
||||
console.log('[PDF] saving', filename);
|
||||
pdf.save(filename);
|
||||
console.log('[PDF] save triggered');
|
||||
} catch (e) {
|
||||
console.error('PDF export failed', e);
|
||||
openPrintFallback('PDF-Download fehlgeschlagen – nutze Druckdialog als Fallback.');
|
||||
console.error('[PDF] export failed', e);
|
||||
openPrintFallback('PDF-Download fehlgeschlagen – nutze Druckdialog als Fallback. Schau in die Browser-Konsole.');
|
||||
} finally {
|
||||
root.remove();
|
||||
console.log('[PDF] cleanup done');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function syncActiveJob(){
|
||||
const r = await fetch('/api/generate/active');
|
||||
const j = await r.json();
|
||||
|
||||
Reference in New Issue
Block a user