css page property « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ css page property ’

Add Page number using Page Property of CSS

Posted by Uday Pratap Singh on August 20th, 2010

In my recent project we need to generate the pdf document from HTML page. We are using iText renderer for doing this. The client had the requirement that each page bottom right need to have number on it. All these things need to be replicated on every page. So for doing this we need to know more about the CSS3 page properties . I found the solution in this documentation http://www.w3.org/TR/css3-page/ and http://www.w3.org/TR/CSS21/generate.html#counters
For doing this I did something like

@page {
        margin-top: 149px;
        margin-left: 2px;
        margin-bottom: 40px;
        margin-right: 2px;
        size: landscape;
        counter-increment: page;
 
     @bottom-right {
padding-right:20px;
        content: "Page " counter(page);
      }
 
    }

Its just so simple we added and incremental page counter in the page property which can be reset as well. As my counter was incrementing after each page so I defined counter-interment at page level, although depending on the cases you can increment the counter before or after occurrence of any element like.

.incrementClass:before {
   counter-increment: page;
}

in above example counter will be incremented before the incrementClass appears on the page.

Hope it helps

## Uday Pratap Singh ##
uday@intelligrape.com

http://www.IntelliGrape.com/
http://in.linkedin.com/in/meudaypratap

  • Share/Bookmark
Posted in Grails, HTML-UI-CSS