Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a working example:</p> <pre><code>package com.sg2net.test; import java.io.FileNotFoundException; import java.io.FileOutputStream; import org.xhtmlrenderer.pdf.ITextRenderer; import com.lowagie.text.DocumentException; public class XHTMLRenderer8 { /** * @author Giovanni Cuccu */ public static void main(String[] args) throws FileNotFoundException, DocumentException { ITextRenderer renderer = new ITextRenderer(); String content="&lt;html&gt;&lt;head&gt;&lt;style&gt;\n" + "div.header {\n" + "display: block; text-align: center;\n" + "position: running(header);}\n" + "div.footer {\n" + "display: block; text-align: center;\n" + "position: running(footer);}\n" + "div.content {page-break-after: always;}" + "@page { @top-center { content: element(header) }}\n " + "@page { @bottom-center { content: element(footer) }}\n" + "&lt;/style&gt;&lt;/head&gt;\n" + "&lt;body&gt;&lt;div class='header'&gt;Header&lt;/div&gt;&lt;div class='footer'&gt;Footer&lt;/div&gt;&lt;div class='content'&gt;Page1&lt;/div&gt;&lt;div&gt;Page2&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;"; renderer.setDocumentFromString(content); renderer.layout(); renderer.createPDF(new FileOutputStream("test.pdf")); } } </code></pre> <hr> <p>This is using the following XHTML document</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style&gt; div.header { display: block; text-align: center; position: running(header); } div.footer { display: block; text-align: center; position: running(footer); } div.content {page-break-after: always;} @page { @top-center { content: element(header) } } @page { @bottom-center { content: element(footer) } } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div class='header'&gt;Header&lt;/div&gt; &lt;div class='footer'&gt;Footer&lt;/div&gt; &lt;div class='content'&gt;Page1&lt;/div&gt; &lt;div&gt;Page2&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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