Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating page headers and footers using CSS for print

I'm creating a PDF using Flying Saucer (which dumps out CSS/HTML to iText to a PDF) and I'm trying to use CSS3 to apply an image header and footer to each page.

I'd essentially like to put this div in the top left of each page:

<div id="pageHeader">     <img src="..." width="250" height="25"/> </div> 

My CSS looks somewhat like this:

@page {     size: 8.5in 11in;     margin: 0.5in;      @top-left {         content: "Hello";     } } 

Is there a way for me to put this div in the content?

like image 508
Naftuli Kay Avatar asked Mar 15 '12 22:03

Naftuli Kay


People also ask

How do I create a header and footer in CSS?

Answer: Use CSS fixed positioning You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.

How do you write a print page in CSS?

HTML, CSS and JavaScript You can use CSS to change the appearance of your web page when it's printed on a paper. You can specify one font for the screen version and another for the print version. You have seen @media rule in previous chapters. This rule allows you to specify different style for different media.

How do I create a custom header in CSS?

Control the look and feel of the header and footer of your site with your CSS. To edit your CSS, click "Edit" at the right of the "Custom Header / Footer CSS" field under the "Appearance" tab of your Management Console.


1 Answers

Putting an element to the top of each page:

@page {   @top-center {     content: element(pageHeader);   } } #pageHeader{   position: running(pageHeader); } 

See http://www.w3.org/TR/css3-gcpm/#running-elements (works in Flying Saucer)

like image 62
Adam Avatar answered Oct 02 '22 16:10

Adam