diff --git a/blocksuite/affine/shared/src/utils/print-to-pdf.ts b/blocksuite/affine/shared/src/utils/print-to-pdf.ts index 61a656e5de..a94e00d4c8 100644 --- a/blocksuite/affine/shared/src/utils/print-to-pdf.ts +++ b/blocksuite/affine/shared/src/utils/print-to-pdf.ts @@ -17,7 +17,14 @@ export async function printToPdf( return new Promise((resolve, reject) => { const iframe = document.createElement('iframe'); document.body.append(iframe); - iframe.style.display = 'none'; + // Use a hidden but rendering-enabled state instead of display: none + Object.assign(iframe.style, { + visibility: 'hidden', + position: 'absolute', + width: '0', + height: '0', + border: 'none', + }); iframe.srcdoc = ''; iframe.onload = async () => { if (!iframe.contentWindow) { @@ -28,6 +35,44 @@ export async function printToPdf( reject(new Error('Root element not defined, unable to print pdf')); return; } + + const doc = iframe.contentWindow.document; + + doc.write(``); + doc.close(); iframe.contentWindow.document .write(`