Is there a plan to support counter-reset?
I have to generate a pdf combined of a lot of reports for different students. Each report needs to have individual page numbers, i.e. not 1/117 thru 117/117 but instead each one would have numbers relative to just that one report, more like 1/5 thru 5/5 and so on.
So optimally counter-reset: page; should reset the counter to 1 and also make the counter(pages) evaluate correctly the number of pages since the last reset.
Is that even doable?
As a backup plan, do you know of any commandline tool to merge multiple pdf's into one that installs on centos?
Thanks for a superb tool btw.
Hi. In this case I’d recommend using the low-level API to render multiple document separately, then write them to a single PDF file. Something like this:
documents = [HTML(string=render_template(student)).render() for student in students]
documents.copy([page for doc in documents for page in doc.pages]).write_pdf(target)
Note: PDFtk can also concatenate PDF files, but that’s probably less efficient than the above as it’s just doing more work.
Even with named page, you’d still need more CSS features (like a new page selector) to only reset the page counter on the first page for a given student.
The low-level API (separating the layout into pages form the painting and PDF writing) was designed for this kind thing, and is already supported. What feature do you mean exactly?
Hi, sorry to be unclear.
I may have misunderstood the css page standard (http://dev.w3.org/csswg/css-page/#page-based-counters)
I thought I could simply wrap each "subreport" like this:
... report content ...
... report content ...
and in the css I'd write:
And this would have the effect that each student-report would have it's own page numbers and page count.
I find the spec a bit unclear on this point, but I’m told that this wouldn’t work because of the scoping rules. Your explicit counter-reset would create one scope, and the implicit increment in @page would be a new scope, so that you actually have two page counters.
Maybe we should fix the spec to allow this use case.
I would love to see this supported in WeasyPrint. The only html to pdf renderer I have found that supports this is PrinceXML. Below is an example document that should have 5 total pages with 2 separate counters each having 3 and 2 total pages. Here is a pdf that I generated using the html below.
counter-reset:page 1 pages 1;
content: "Page " counter(page) " of " counter(pages);
this should be page 1/3
this should be page 2/3
this should be page 3/3
this should be page 1/2
this should be page 2/2
It would be really sweet if weasyprint could use counter-reset at all - so far I'm surprised to see just how much can actually be done, and this seems to be the only immediate drawback. :)