Is it possible to do fancy formatting for page footers with weasyprint?

formatting, pdf, python, weasyprint

Solution

"Page 1 of 4" is not doable at the moment. If you’re interested, please send comments to www-style@w3.org about what a new CSS feature could look like to do this kind of thing.

What works is:

- Page-margin rules like `@bottom-right`, with the `content` property. You get up to 16 such boxes per page, but parts of one box can not be styled differently.

- Elements with `position: fixed` are repeated on every page. With tricks like `top: 100%; right: 0` you can position them like headers or footers, but they are identical on every page. `counter(page)` doesn’t work there.

By the way, I do not usually watch StackOverflow for WeasyPrint question. Writing to WeasyPrint’s mailing list or issue tracker will get more response.

Problem

weasyprint understands certain custom css directives, such as: ``` @bottom-right { content: "Page " counter(page) " of " counter(pages) " } ``` which places a "Page 1 of 4" style counter at the bottom right of each pdf page weasyprint generates. I'd like to produce slightly fancier formatting for my footers - for example, I'd like to be able to show some portions in bold, and others as italic, like so: Page 1 of 4 Is this feasible with weasyprint? If so, how do I instruct weasyprint to use this kind of formatting - I'll take CSS based solutions, though I'd much rather do this programmatically using the weasyprint library from python.

Original source