fix: PDF export using hidden iframe for reliable print dialog

This commit is contained in:
admin
2026-03-18 21:54:32 +00:00
Unverified
parent 72a786b1b6
commit 4e981ae7f8

View File

@@ -240,14 +240,26 @@ export function downloadSeoReport(d: SeoAuditData, format: "html" | "pdf") {
document.body.removeChild(a); document.body.removeChild(a);
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
} else { } else {
const blob = new Blob([html], { type: "text/html" }); const iframe = document.createElement("iframe");
const url = URL.createObjectURL(blob); iframe.style.position = "fixed";
const win = window.open(url, "_blank"); iframe.style.right = "0";
if (win) { iframe.style.bottom = "0";
win.addEventListener("load", () => { iframe.style.width = "0";
setTimeout(() => win.print(), 300); iframe.style.height = "0";
}); iframe.style.border = "none";
document.body.appendChild(iframe);
const doc = iframe.contentDocument || iframe.contentWindow?.document;
if (doc) {
doc.open();
doc.write(html);
doc.close();
iframe.onload = () => {
setTimeout(() => {
iframe.contentWindow?.focus();
iframe.contentWindow?.print();
setTimeout(() => document.body.removeChild(iframe), 5000);
}, 600);
};
} }
setTimeout(() => URL.revokeObjectURL(url), 60000);
} }
} }