Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.23k stars 686 forks source link

Use page counter style and value in PDF page numbers #1205

Open arikrupnik opened 4 years ago

arikrupnik commented 4 years ago

Is the interaction between the page counter and bookmark-level index part of the standard?

I have a document that starts on page 31. I can use @page:first { counter-reset: page 31; } and content: counter(page) works correctly. However, the page numbers in the sidebar TOC still count from 1.

Do I have any control over that?

liZe commented 4 years ago

Do I have any control over that?

You currently don’t, but there’s hope.

There’s a way to change the page numbers directly in the PDF document. This way, your first page would have number 31, and the TOC would be updated accordingly. The PDF specification document itself uses this feature to have Roman numerals at the beginning, and start at "1" on page 9.

PDF readers have the responsability to handle these numbers correctly, but the ones I’ve tested (pdf.js and Evince) handle them correctly.

When Cairo is gone (good news coming really, really, really soon), we’ll be able to implement this feature by hacking the PDF with our bare hands.

arikrupnik commented 4 years ago

I see what you mean. My PDF viewer seems to display it correctly.

I didn't know you were phasing out Cairo.Is it too focused on interactive rendering and treats PDF as too much of an afterthought? I'll be watching this space for updates!

PDF32000_2008

liZe commented 4 years ago

I didn't know you were phasing out Cairo.Is it too focused on interactive rendering and treats PDF as too much of an afterthought?

Cairo is an incredible library, but we’ll always miss a low-level access to the PDF internals for a lot of features (like this one). We’ve also had to live with many small bugs for a looooong time, because you can wait for years (!) before a new version is released.

(And we sometimes dream of removing all the non-Python dependencies. But that’s just a dream.)