简体   繁体   中英

Sectional page count with flying saucer and css

I am using flying saucer for generating PDF report from a web HTML. My report contains multiple sections and each section may or may not occupy multiple pages in the report

My requirement is to show section page count in the Header

-----------HEADER-----------
     My Fancy Report
     First Section (Page 1)
-----------------------------
.
. First Section (conitinued)
.
-----------HEADER-----------
     My Fancy Report
     First Section (Page 2)
-----------------------------
.
. First Section (Completed)
.
 -----------HEADER-----------
     My Fancy Report
     Second Section (Page 1)
-----------------------------
.
. Second Section 
.

I tried using a counter like below

header { counter-increment: myCounter; }
header:after{content: ' (Page ' counter(myCounter) ')' ;}
#page{ counter-reset: myCounter; }

#page is an element which occurs on every start of new section

Doing this, I never see counter is reset with new section.

Seems like the counter-reset doesn't work with flying-saucer, that's what I read somewhere.

Can anyone let me know, what is the best way to achieve this?

As counter-reset doesn't work correctly with Flying-sacuer, I found a simple workaround. Hope this will help others

As mentioned in my question I have multiple running Headers (sectional headers) in my document. I create a separate counter for each of the sectional header and increment them independently.

#sectionOneHeader{ counter-increment: sectionOneCounter; }
#sectionOneHeader:after{ content: ' (Page ' counter(sectionOneCounter) ') '; }

#sectionTwoHeader{ counter-increment: sectionTwoCounter; }
#sectionTwoHeader:after{ content: ' (Page ' counter(sectionTwoCounter) ') '; }

and this worked exactly the way I wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM