Weasyprint PDF export page counter not working #5246

Closed
opened 2026-02-05 09:51:08 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @Pafzedog on GitHub (Apr 4, 2025).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

Hello,
working to add header and footer to exported PDF as showed in this gist whith success but I recently decided to use weasyprint in place of the native PDF renderer and all exported pages have number "1" .
I have the feeling it should be related to the CSS that is not processed correctly by weasyprint but I have no clue and no such skills to find out what is going on.

Exact BookStack Version

v25.02.1

Log Content

No response

Hosting Environment

docker

Originally created by @Pafzedog on GitHub (Apr 4, 2025). ### Attempted Debugging - [x] I have read the debugging page ### Searched GitHub Issues - [x] I have searched GitHub for the issue. ### Describe the Scenario Hello, working to add header and footer to exported PDF as showed in [this gist ](https://gist.github.com/ssddanbrown/bcc9d2e73ec8144a7f4807fd10ddc863) whith success but I recently decided to use weasyprint in place of the native PDF renderer and all exported pages have number "1" . I have the feeling it should be related to the CSS that is not processed correctly by weasyprint but I have no clue and no such skills to find out what is going on. ### Exact BookStack Version v25.02.1 ### Log Content _No response_ ### Hosting Environment docker
OVERLORD added the 🐕 Support label 2026-02-05 09:51:08 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Apr 5, 2025):

Hi @Pafzedog,
Yeah, these kind of elements often come down to the specific support of the PDF renderer used.

I have not tried it but it looks like weasyprint may support the more recent @page at-rules in css.

So maybe something like:

<style>
@page {
  @bottom-right {
    content: "Page " counter(page);
  }
}
</style>

According to the spec, the page counter (as used above) should be defined to represent the current page, and there's also a pages counter for the total number of pages in the document.

@ssddanbrown commented on GitHub (Apr 5, 2025): Hi @Pafzedog, Yeah, these kind of elements often come down to the specific support of the PDF renderer used. I have not tried it but it looks like weasyprint may support the more recent [@page at-rules](https://developer.mozilla.org/en-US/docs/Web/CSS/@page) in css. So maybe something like: ```html <style> @page { @bottom-right { content: "Page " counter(page); } } </style> ``` [According to the spec](https://drafts.csswg.org/css-page-3/#page-based-counters), the `page` counter (as used above) should be defined to represent the current page, and there's also a `pages` counter for the total number of pages in the document.
Author
Owner

@Pafzedog commented on GitHub (Apr 7, 2025):

Hi @ssddanbrown ,
thank you for answering.
With a little help from my friend, I tried exactly what you said and, with some adjustements (margin, padding, font-size, color and family), I was able to add page counter with total number of pages. 🚀

@Pafzedog commented on GitHub (Apr 7, 2025): Hi @ssddanbrown , thank you for answering. With a little help from my friend, I tried exactly what you said and, with some adjustements (margin, padding, font-size, color and family), I was able to add page counter with total number of pages. 🚀
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#5246