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
?
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With