fix: PDF export using hidden iframe for reliable print dialog
This commit is contained in:
@@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user