rkusa / pdfjs

A Portable Document Format (PDF) generation library targeting both the server- and client-side.
MIT License
774 stars 142 forks source link

Show header on all pages except page 1 #230

Open psalaets opened 4 years ago

psalaets commented 4 years ago

This is a feature request for a future version.

I am trying to generate a header that is conditional on page number, but doesn't contain the page number. My use case is: show a header on all pages except for the first page.

header.pageNumber(fn) is very close to what I need but it requires the header to be different when the total pages is different. Otherwise you get an automatically generated header containing the page number.

I found a way to make it work but I am depending on private APIs:

const header = doc.header();
header.pageNumber((current, total) => {
  if (doc._currentPage) {
    return String(total);
  } else {
    return current === 1 ? '' : 'header content here'
  }
});

Thanks

rkusa commented 4 years ago

Thanks for the feature request! That is actually something I have somewhere in my backlog, too. 😌