fix: visibility issue of document in print mode (#14367)

fix #14330 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved print-to-PDF rendering by enforcing a consistent light theme,
ensuring better readability and visual consistency in exported PDF
documents.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Fahleen Arif
2026-02-02 22:52:14 +05:00
committed by GitHub
parent 12f0a9ae62
commit e2b26ffb0c

View File

@@ -35,9 +35,28 @@ export async function printToPdf(
overflow: initial !important; overflow: initial !important;
print-color-adjust: exact; print-color-adjust: exact;
-webkit-print-color-adjust: exact; -webkit-print-color-adjust: exact;
color: #000 !important;
background: #fff !important;
color-scheme: light !important;
} }
::-webkit-scrollbar { ::-webkit-scrollbar {
display: none; display: none;
}
:root, body {
--affine-text-primary: #000 !important;
--affine-text-secondary: #111 !important;
--affine-text-tertiary: #333 !important;
--affine-background-primary: #fff !important;
--affine-background-secondary: #fff !important;
--affine-background-tertiary: #fff !important;
}
body, [data-theme='dark'] {
color: #000 !important;
background: #fff !important;
}
body * {
color: #000 !important;
-webkit-text-fill-color: #000 !important;
} }
:root { :root {
--affine-note-shadow-box: none !important; --affine-note-shadow-box: none !important;
@@ -95,6 +114,14 @@ export async function printToPdf(
true true
) as HTMLDivElement; ) as HTMLDivElement;
// force light theme in print iframe
iframe.contentWindow.document.documentElement.setAttribute(
'data-theme',
'light'
);
iframe.contentWindow.document.body.setAttribute('data-theme', 'light');
importedRoot.setAttribute('data-theme', 'light');
// draw saved canvas image to canvas // draw saved canvas image to canvas
const allImportedCanvas = importedRoot.getElementsByTagName('canvas'); const allImportedCanvas = importedRoot.getElementsByTagName('canvas');
for (const importedCanvas of allImportedCanvas) { for (const importedCanvas of allImportedCanvas) {