💄 hide running headings on title pages
This commit is contained in:
@@ -624,26 +624,28 @@ export function registerIpcHandlers(): void {
|
|||||||
const mergedPdf = await PDFDocument.create()
|
const mergedPdf = await PDFDocument.create()
|
||||||
const headerStandardFont = opts.font === 'courier' ? StandardFonts.Courier : StandardFonts.TimesRoman
|
const headerStandardFont = opts.font === 'courier' ? StandardFonts.Courier : StandardFonts.TimesRoman
|
||||||
const headerFont = await mergedPdf.embedFont(headerStandardFont)
|
const headerFont = await mergedPdf.embedFont(headerStandardFont)
|
||||||
// pageOwners[i] tracks the section title and whether the page is a cover page
|
// pageOwners[i] tracks the section title, whether the page is a cover page,
|
||||||
const pageOwners: { title: string; isCover: boolean }[] = []
|
// 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) {
|
for (const { title, buffer, isCover } of sectionPdfs) {
|
||||||
const srcPdf = await PDFDocument.load(buffer)
|
const srcPdf = await PDFDocument.load(buffer)
|
||||||
const copied = await mergedPdf.copyPages(srcPdf, srcPdf.getPageIndices())
|
const copied = await mergedPdf.copyPages(srcPdf, srcPdf.getPageIndices())
|
||||||
for (const page of copied) {
|
for (const [pageIdx, page] of copied.entries()) {
|
||||||
mergedPdf.addPage(page)
|
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.
|
// Page numbers count from 1 starting with the first non-cover page.
|
||||||
const allPages = mergedPdf.getPages()
|
const allPages = mergedPdf.getPages()
|
||||||
let bodyPageNum = 0
|
let bodyPageNum = 0
|
||||||
for (let i = 0; i < allPages.length; i++) {
|
for (let i = 0; i < allPages.length; i++) {
|
||||||
if (pageOwners[i].isCover) continue // no header/number on cover page
|
if (pageOwners[i].isCover) continue // no header/number on cover page
|
||||||
bodyPageNum++
|
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 page = allPages[i]
|
||||||
const { width, height } = page.getSize()
|
const { width, height } = page.getSize()
|
||||||
const chapterUpper = pageOwners[i].title.toUpperCase()
|
const chapterUpper = pageOwners[i].title.toUpperCase()
|
||||||
|
|||||||
Reference in New Issue
Block a user