Search in sources :

Example 1 with RtfTotalPageNumber

use of com.lowagie.text.rtf.field.RtfTotalPageNumber in project javamelody by javamelody.

the class MRtfWriter method createWriter.

/**
 * We create a writer that listens to the document and directs a RTF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 */
@Override
protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) {
    final RtfWriter2 writer = RtfWriter2.getInstance(document, out);
    // title
    final String title = buildTitle(table);
    if (title != null) {
        final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title));
        header.setAlignment(Element.ALIGN_LEFT);
        header.setBorder(Rectangle.NO_BORDER);
        document.setHeader(header);
        document.addTitle(title);
    }
    // advanced page numbers : x/y
    final Paragraph footerParagraph = new Paragraph();
    final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
    footerParagraph.add(new RtfPageNumber(font));
    footerParagraph.add(new Phrase(" / ", font));
    footerParagraph.add(new RtfTotalPageNumber(font));
    footerParagraph.setAlignment(Element.ALIGN_CENTER);
    final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
    footer.setBorder(Rectangle.TOP);
    document.setFooter(footer);
    return writer;
}
Also used : RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) HeaderFooter(com.lowagie.text.HeaderFooter) RtfHeaderFooter(com.lowagie.text.rtf.headerfooter.RtfHeaderFooter) RtfTotalPageNumber(com.lowagie.text.rtf.field.RtfTotalPageNumber) Phrase(com.lowagie.text.Phrase) Font(com.lowagie.text.Font) RtfWriter2(com.lowagie.text.rtf.RtfWriter2) Paragraph(com.lowagie.text.Paragraph) RtfPageNumber(com.lowagie.text.rtf.field.RtfPageNumber)

Example 2 with RtfTotalPageNumber

use of com.lowagie.text.rtf.field.RtfTotalPageNumber in project itext2 by albfernandez.

the class TotalPageNumberTest method main.

/**
 * Demonstrates creating a header with page number and total number of pages
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("TotalPageNumber.rtf"));
    // Create a new Paragraph for the footer
    Paragraph par = new Paragraph("Page ");
    // Add the RtfPageNumber to the Paragraph
    par.add(new RtfPageNumber());
    // Add the RtfTotalPageNumber to the Paragraph
    par.add(" of ");
    par.add(new RtfTotalPageNumber());
    // Create an RtfHeaderFooter with the Paragraph and set it
    // as a header for the document
    RtfHeaderFooter header = new RtfHeaderFooter(par);
    document.setHeader(header);
    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) RtfTotalPageNumber(com.lowagie.text.rtf.field.RtfTotalPageNumber) Document(com.lowagie.text.Document) Paragraph(com.lowagie.text.Paragraph) RtfPageNumber(com.lowagie.text.rtf.field.RtfPageNumber) Test(org.junit.Test)

Aggregations

Paragraph (com.lowagie.text.Paragraph)2 RtfPageNumber (com.lowagie.text.rtf.field.RtfPageNumber)2 RtfTotalPageNumber (com.lowagie.text.rtf.field.RtfTotalPageNumber)2 RtfHeaderFooter (com.lowagie.text.rtf.headerfooter.RtfHeaderFooter)2 Document (com.lowagie.text.Document)1 Font (com.lowagie.text.Font)1 HeaderFooter (com.lowagie.text.HeaderFooter)1 Phrase (com.lowagie.text.Phrase)1 RtfWriter2 (com.lowagie.text.rtf.RtfWriter2)1 Test (org.junit.Test)1