From ff40d424aa5d2321cba2a3e6730900579b7c672f Mon Sep 17 00:00:00 2001 From: TC Date: Mon, 22 Jun 2026 21:56:50 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20hide=20running=20headings=20on?= =?UTF-8?q?=20title=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/ipcHandlers.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/ipcHandlers.ts b/src/main/ipcHandlers.ts index 8975a3e..e219913 100644 --- a/src/main/ipcHandlers.ts +++ b/src/main/ipcHandlers.ts @@ -624,26 +624,28 @@ export function registerIpcHandlers(): void { const mergedPdf = await PDFDocument.create() const headerStandardFont = opts.font === 'courier' ? StandardFonts.Courier : StandardFonts.TimesRoman const headerFont = await mergedPdf.embedFont(headerStandardFont) - // pageOwners[i] tracks the section title and whether the page is a cover page - const pageOwners: { title: string; isCover: boolean }[] = [] + // pageOwners[i] tracks the section title, whether the page is a cover page, + // and whether it is the first page of its section (chapter/part opener). + const pageOwners: { title: string; isCover: boolean; isSectionOpener: boolean }[] = [] for (const { title, buffer, isCover } of sectionPdfs) { const srcPdf = await PDFDocument.load(buffer) const copied = await mergedPdf.copyPages(srcPdf, srcPdf.getPageIndices()) - for (const page of copied) { + for (const [pageIdx, page] of copied.entries()) { mergedPdf.addPage(page) - pageOwners.push({ title, isCover }) + pageOwners.push({ title, isCover, isSectionOpener: pageIdx === 0 }) } } - // Stamp the running header on body pages only (cover page gets no header). + // Stamp the running header on body pages only (cover page and section opener + // pages get no header — opener pages show the chapter/part title instead). // Page numbers count from 1 starting with the first non-cover page. const allPages = mergedPdf.getPages() let bodyPageNum = 0 for (let i = 0; i < allPages.length; i++) { if (pageOwners[i].isCover) continue // no header/number on cover page bodyPageNum++ - if (bodyPageNum === 1) continue // no running header on first body page + if (pageOwners[i].isSectionOpener) continue // no running header on chapter/part opener pages const page = allPages[i] const { width, height } = page.getSize() const chapterUpper = pageOwners[i].title.toUpperCase()