Search in sources :

Example 6 with RtfHeaderFooter

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();
}
Also used : RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) Document(com.lowagie.text.Document) Paragraph(com.lowagie.text.Paragraph) RtfPageNumber(com.lowagie.text.rtf.field.RtfPageNumber) Test(org.junit.Test)

Example 7 with RtfHeaderFooter

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();
}
Also used : RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) HeaderFooter(com.lowagie.text.HeaderFooter) RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) Chapter(com.lowagie.text.Chapter) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) Paragraph(com.lowagie.text.Paragraph) Test(org.junit.Test)

Aggregations

Paragraph (com.lowagie.text.Paragraph)7 RtfHeaderFooter (com.lowagie.text.rtf.headerfooter.RtfHeaderFooter)7 Document (com.lowagie.text.Document)6 Test (org.junit.Test)6 RtfPageNumber (com.lowagie.text.rtf.field.RtfPageNumber)5 HeaderFooter (com.lowagie.text.HeaderFooter)3 Phrase (com.lowagie.text.Phrase)3 Cell (com.lowagie.text.Cell)2 Chapter (com.lowagie.text.Chapter)2 Table (com.lowagie.text.Table)2 RtfWriter2 (com.lowagie.text.rtf.RtfWriter2)2 RtfTotalPageNumber (com.lowagie.text.rtf.field.RtfTotalPageNumber)2 RtfHeaderFooterGroup (com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup)2 Anchor (com.lowagie.text.Anchor)1 Annotation (com.lowagie.text.Annotation)1 Chunk (com.lowagie.text.Chunk)1 Font (com.lowagie.text.Font)1 Image (com.lowagie.text.Image)1 List (com.lowagie.text.List)1 ListItem (com.lowagie.text.ListItem)1