revert: restore previously working PDF export implementation
This commit is contained in:
@@ -498,17 +498,8 @@ function closeAiModal(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function downloadPdf(){
|
async function downloadPdf(){
|
||||||
const fallbackWin = window.open('', '_blank');
|
|
||||||
const openPrintFallback = (msg='') => {
|
|
||||||
if (msg) alert(msg);
|
|
||||||
if (!fallbackWin) return;
|
|
||||||
fallbackWin.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title></head><body>${app.innerHTML}</body></html>`);
|
|
||||||
fallbackWin.document.close();
|
|
||||||
fallbackWin.onload = () => setTimeout(() => fallbackWin.print(), 200);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!window.html2canvas || !window.jspdf?.jsPDF) {
|
if (!window.html2canvas || !window.jspdf?.jsPDF) {
|
||||||
openPrintFallback('PDF-Export-Bibliothek nicht geladen. Nutze Fallback-Druckdialog.');
|
alert('PDF-Export-Bibliothek nicht geladen.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,15 +533,12 @@ async function downloadPdf(){
|
|||||||
const usableH = pageH - margin * 2;
|
const usableH = pageH - margin * 2;
|
||||||
|
|
||||||
for (let i = 0; i < cards.length; i++) {
|
for (let i = 0; i < cards.length; i++) {
|
||||||
const canvas = await Promise.race([
|
const canvas = await window.html2canvas(cards[i], {
|
||||||
window.html2canvas(cards[i], {
|
scale: 2,
|
||||||
scale: 2,
|
useCORS: true,
|
||||||
useCORS: true,
|
backgroundColor: '#ffffff',
|
||||||
backgroundColor: '#ffffff',
|
logging: false
|
||||||
logging: false
|
});
|
||||||
}),
|
|
||||||
new Promise((_, rej) => setTimeout(() => rej(new Error('Render timeout')), 15000))
|
|
||||||
]);
|
|
||||||
const img = canvas.toDataURL('image/jpeg', 0.98);
|
const img = canvas.toDataURL('image/jpeg', 0.98);
|
||||||
const imgW = canvas.width;
|
const imgW = canvas.width;
|
||||||
const imgH = canvas.height;
|
const imgH = canvas.height;
|
||||||
@@ -565,10 +553,6 @@ async function downloadPdf(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
pdf.save(`coachingcards-${new Date().toISOString().slice(0,10)}.pdf`);
|
pdf.save(`coachingcards-${new Date().toISOString().slice(0,10)}.pdf`);
|
||||||
if (fallbackWin && !fallbackWin.closed) fallbackWin.close();
|
|
||||||
} catch (e) {
|
|
||||||
console.error('PDF export failed', e);
|
|
||||||
openPrintFallback('PDF-Export fehlgeschlagen – öffne Druckdialog als Fallback.');
|
|
||||||
} finally {
|
} finally {
|
||||||
root.remove();
|
root.remove();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user