Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page numbers with CSS/HTML

Tags:

html

css

printing

An interesting use case has popped up for us, we are requiring that when we print a website the printed copy will have a page header and footer, and inside the footer the page number.

Anyone got any idea how to achieve this?

Note: Browser version can be the latest of anything, clients are other web developers.

like image 623
balupton Avatar asked May 24 '11 11:05

balupton


People also ask

How do I add page numbers in HTML CSS?

If you are looking to add page numbers when printing under Chrome/Chromium, one easy solution is to use Paged. js. This JS library takes your HTML/CSS and cuts it into pages, ready to print as a book, that you will preview in your browser. It makes the @page and most the CSS3 specifications work for Chrome.

How do I add page numbers to a footer in HTML?

Refer to Adding Content to a Header or Footer for an example of how to create content for a header or footer. 2. Highlight numbered-header then the Edit button to open the Generated Text Editor. Place your cursor in the right hand cell of the header table, then choose Insert > Page Number.

How do I count pages in HTML?

There is no way to get a counter total with CSS counters so the only way I can think of getting the output you require is to duplicate the HTML (which may not be a big problem if the content is dynamically generated). Output the HTML once to get the total number of pages then again to get the current page.

Does HTML have page numbers?

You can add in header and footer any PDF element that you can add in a PDF page : HTML, text, image. Even more you can add page numbering in HTML elements from header and footer. The Full Description and a Code Sample can be accessed from the top tabs.


1 Answers

Depending on your required browser support.

@page {   @bottom-right {     content: counter(page) " of " counter(pages);   } } 

Further reading:

  • http://www.w3.org/TR/css3-page/
  • http://www.intelligrape.com/blog/2010/08/20/add-page-number-using-page-property-of-css/
  • http://www.princexml.com/doc/6.0/page-numbers/
like image 164
alex Avatar answered Oct 03 '22 01:10

alex