use of com.lowagie.text.rtf.headerfooter.RtfHeaderFooter in project itext2 by albfernandez.
the class PageNumberTest method main.
/**
* Demonstrates creating a footer with the current page number
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("PageNumber.rtf"));
// Create a new Paragraph for the footer
Paragraph par = new Paragraph("Page ");
par.setAlignment(Element.ALIGN_RIGHT);
// Add the RtfPageNumber to the Paragraph
par.add(new RtfPageNumber());
// Create an RtfHeaderFooter with the Paragraph and set it
// as a footer for the document
RtfHeaderFooter footer = new RtfHeaderFooter(par);
document.setFooter(footer);
document.open();
for (int i = 1; i <= 300; i++) {
document.add(new Paragraph("Line " + i + "."));
}
document.close();
}
use of com.lowagie.text.rtf.headerfooter.RtfHeaderFooter in project itext2 by albfernandez.
the class ChapterHeaderFooterTest method main.
/**
* Different headers and footers per Chapter example.
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ChapterHeaderFooter.rtf"));
// Create the header identifying the current chapter. The first
// chapter has to be set before the document is opened.
Paragraph header = new Paragraph("Chapter 1");
header.setAlignment(Element.ALIGN_CENTER);
document.setHeader(new RtfHeaderFooter(header));
// If the footer (or header) is to be the same for all Chapters
// then it has to be set before the document is opened and is
// then automatically set for all Chapters.
document.setFooter(new HeaderFooter(new Phrase("This is page "), new Phrase(".")));
document.open();
Chapter chapter1 = new Chapter("Chapter 1", 1);
chapter1.add(new Paragraph("This document has different headers and footers " + " for each chapter."));
document.add(chapter1);
// After adding the first chapter set the header for the second chapter.
header = new Paragraph("Chapter 2");
header.setAlignment(Element.ALIGN_CENTER);
document.setHeader(new RtfHeaderFooter(header));
Chapter chapter2 = new Chapter("Chapter 2", 2);
chapter2.add(new Paragraph("This is the content of chapter 2."));
document.add(chapter2);
// After adding the second chapter set the header for the third chapter.
header = new Paragraph("Chapter 3");
header.setAlignment(Element.ALIGN_CENTER);
document.setHeader(new RtfHeaderFooter(header));
Chapter chapter3 = new Chapter("Chapter 3", 3);
chapter3.add(new Paragraph("Chapter 3 is very boring."));
document.add(chapter3);
document.close();
}
Aggregations