Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating header/footer with flying saucer (xHTMLRenderer) and iText
    primarykey
    data
    text
    <p>I realize this question has been asked before (I looked at all the solutions and tried them all) but I am still trying to generate a pdf document with a header and footer that repeat on every page. </p> <p>I am using <code>flying saucer</code> R8 with <code>iText2.0.8</code> I have tried many different methods to get it working but so far to no avail. Some methods I tested out were <a href="https://gist.github.com/626264" rel="noreferrer">https://gist.github.com/626264</a>, using running elements and margin boxs <a href="http://pigeonholdings.com/projects/flyingsaucer/R8/doc/guide/users-guide-R8.html#xil_40" rel="noreferrer">http://pigeonholdings.com/projects/flyingsaucer/R8/doc/guide/users-guide-R8.html#xil_40</a> (css3 feature), a guide for flying saucer r7 that doesn't work for r8 <a href="http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html#page-specific-features" rel="noreferrer">http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html#page-specific-features</a>, a long with many other methods which did not work for me. </p> <p>My header <code>div</code> contains 2 other divs with images and my footer is just for page numbering. The html is being put into a <code>StringBuffer</code> called buf.</p> <pre><code>buf.append("&lt;head&gt;"); buf.append("&lt;title&gt;blabla&lt;/title&gt; "); buf.append("&lt;style type='text/css' media='print'&gt; "); buf.append("@page { size:8.5in 11in; padding:1em; @bottom-left { content: element(footer); } } "); buf.append("#footer { font-size: 90%; font-style: italic; position: running(footer); top: 0; left: 0; }"); buf.append("#pagenumber:before { content: counter(page); } "); buf.append("#pagecount:before { content: counter(pages); } "); buf.append("&lt;/style&gt;&lt;/head&gt;"); buf.append("&lt;body&gt;"); buf.append("&lt;div class='header' style='clear:both;'&gt;"); buf.append("&lt;div id='moneyLogo' style='float:left'&gt;"); buf.append("&lt;img src='logo.jpg' alt='Some alt text' /&gt;"); buf.append("&lt;/div&gt;"); buf.append("&lt;div id='canLogo' style='float:right'&gt;"); buf.append("&lt;img src='someImg.gif' alt='alt text' /&gt;"); buf.append("&lt;/div&gt;"); buf.append("&lt;h3 style='text-align:center; clear:both;'&gt;alt text&lt;/h3&gt;"); buf.append("&lt;div style='text-align:center;'&gt;"); buf.append("Some texy text"); buf.append("&lt;br /&gt;");); buf.append("&lt;/div&gt;"); buf.append("&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;"); buf.append("&lt;div id='footer'&gt; Page &lt;span id='pagenumber'/&gt; of &lt;span id='pagecount'/&gt; &lt;/div&gt;"); buf.append("&lt;/body&gt;"); buf.append("&lt;/html&gt;"); </code></pre> <p>My pdf generates fine except for the fact that the header only appears on the first page and the footer only appears on the bottom of the last page. When I put the html through the w3c validator it came out fine, but when I used their CSS validator it said that their were parse errors in the line <code>@page { size:8.5in 11in; padding:1em; @bottom-left { content: element(footer); } }</code> </p> <p>As far as I could tell from all the guides I was reading this was fine. I also heard that the W3C CSS validator was incomplete for CSS3 specs so I assumed it was the validator who was wrong. </p> <p>If anyone could give me some tips of where to look or ideas it would make my week :) </p> <p>p.s. Has to use Flying saucer R8 and/or iText 2.0.8</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload