feat: real PDF file export via html2pdf download
This commit is contained in:
@@ -72,6 +72,7 @@ body.modal-open { overflow: hidden; }
|
|||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://uicdn.toast.com/editor/latest/toastui-editor.min.css" />
|
<link rel="stylesheet" href="https://uicdn.toast.com/editor/latest/toastui-editor.min.css" />
|
||||||
<script src="https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js"></script>
|
<script src="https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
|
||||||
</head><body>
|
</head><body>
|
||||||
<div class="topbar">
|
<div class="topbar">
|
||||||
<button id="menuToggle" class="menu-btn">☰</button>
|
<button id="menuToggle" class="menu-btn">☰</button>
|
||||||
@@ -494,14 +495,27 @@ function closeAiModal(){
|
|||||||
document.body.classList.remove('modal-open');
|
document.body.classList.remove('modal-open');
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadPdf(){
|
async function downloadPdf(){
|
||||||
const printWin = window.open('', '_blank');
|
if (!window.html2pdf) {
|
||||||
if (!printWin) return;
|
alert('PDF-Export-Bibliothek nicht geladen.');
|
||||||
const cardsHtml = app.innerHTML;
|
return;
|
||||||
const css = [...document.querySelectorAll('style')].map(s=>s.textContent||'').join('\n');
|
}
|
||||||
printWin.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title><style>${css}\n.topbar,.sidebar,.card-actions,.modal-actions,.menu-btn{display:none!important;} body{background:#fff!important;padding:0!important;} .main{padding:0!important;} .card-size{margin:0 auto 12px auto!important;box-shadow:none!important;} @media print{.exercise-container{page-break-after:always;}}</style></head><body><div id="app">${cardsHtml}</div></body></html>`);
|
const root = document.createElement('div');
|
||||||
printWin.document.close();
|
root.style.background = '#fff';
|
||||||
printWin.onload = () => setTimeout(() => printWin.print(), 200);
|
root.style.padding = '8px';
|
||||||
|
root.innerHTML = app.innerHTML;
|
||||||
|
root.querySelectorAll('.card-actions,.card-action-btn,button,[data-edit-all]').forEach(el => el.remove());
|
||||||
|
|
||||||
|
const opt = {
|
||||||
|
margin: [8, 8, 8, 8],
|
||||||
|
filename: `coachingcards-${new Date().toISOString().slice(0,10)}.pdf`,
|
||||||
|
image: { type: 'jpeg', quality: 0.96 },
|
||||||
|
html2canvas: { scale: 2, useCORS: true, backgroundColor: '#ffffff' },
|
||||||
|
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
|
||||||
|
pagebreak: { mode: ['css', 'legacy'] }
|
||||||
|
};
|
||||||
|
|
||||||
|
await window.html2pdf().set(opt).from(root).save();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncActiveJob(){
|
async function syncActiveJob(){
|
||||||
|
|||||||
Reference in New Issue
Block a user