Skip to content

Commit a1f8ec6

Browse files
committed
Remove Docusaurus chrome when generating PDFs
Instead of waiting for a timeout, the PDF generator now removes Docusaurus chrome elements from the DOM (navbars, footers, sidebars, breadcrumbs, TOC, pagination, version banners/badges, etc.) before printing to PDF. Updated the PDF stylesheet to include additional navbar/nav-root selectors so the visual reset matches the elements removed. This makes generated PDFs cleaner and more deterministic than relying on a short delay.
1 parent 2cacec5 commit a1f8ec6

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

β€Žscripts/gen-pdf.mjsβ€Ž

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,25 @@ async function generateDocs() {
105105
// Inject our PDF stylesheet
106106
await page.addStyleTag({ content: cssContent });
107107

108-
// Small delay for styles to apply
109-
await new Promise((r) => setTimeout(r, 300));
108+
// Remove chrome elements from the DOM entirely
109+
await page.evaluate(() => {
110+
const selectors = [
111+
'.navbar', '.nav-root', 'nav.navbar',
112+
'footer', '.footer',
113+
'.pagination-nav',
114+
'.theme-doc-sidebar-container',
115+
'.theme-doc-breadcrumbs',
116+
'.theme-doc-toc-mobile',
117+
'.theme-doc-toc-desktop',
118+
'.theme-doc-footer',
119+
'.theme-doc-version-banner',
120+
'.theme-doc-version-badge',
121+
'.col--3',
122+
];
123+
for (const sel of selectors) {
124+
document.querySelectorAll(sel).forEach((el) => el.remove());
125+
}
126+
});
110127

111128
// Print this page to PDF
112129
const pdfBuf = await page.pdf({

β€Žscripts/pdf-style.cssβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
/* ── Reset Docusaurus chrome ─────────────────────────── */
88
.navbar,
9+
.navbar--fixed-top,
10+
.nav-root,
11+
nav.nav-root,
912
.footer,
1013
footer,
1114
.pagination-nav,

0 commit comments

Comments
Β (0)