Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 927a1532fb070c51449654bb68b5bde2 > files > 317

itext-manual-2.0.8-0.0.2mdv2008.1.i586.rpm

/*
 * $Id: ExtendedHeaderFooter.java,v 1.1 2006/10/05 21:25:53 hallm Exp $
 * $Name: HEAD $
 *
 * This code is free software. It may only be copied or modified
 * if you include the following copyright notice:
 *
 * --> Copyright 2006 by Mark Hall <--
 *
 * This code is part of the 'iText Tutorial'.
 * You can find the complete tutorial at the following address:
 * http://itextdocs.lowagie.com/tutorial/
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * itext-questions@lists.sourceforge.net
 */
package com.lowagie.examples.rtf.extensions.hf;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.field.RtfPageNumber;
import com.lowagie.text.rtf.headerfooter.RtfHeaderFooter;

/**
 * The ExtendedHeaderFooter example demonstrates the use of the
 * RtfHeaderFooter object to create more complex headers or footers
 * using more complex elements such as multiple paragraphs or tables.
 * 
 * @version $Revision: 1.1 $
 * @author Mark Hall (mhall@edu.uni-klu.ac.at)
 */
public class ExtendedHeaderFooter {
    /**
     * Extended headers / footers example
     * 
     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates use of the RtfHeaderFooter for extended headers and footers");
        try {
            Document document = new Document();
            RtfWriter2.getInstance(document, new FileOutputStream("ExtendedHeaderFooter.rtf"));

            // Create the Paragraphs that will be used in the header.
            Paragraph date = new Paragraph("01.01.2010");
            date.setAlignment(Paragraph.ALIGN_RIGHT);
            Paragraph address = new Paragraph("TheFirm\nTheRoad 24, TheCity\n" +
                    "+00 99 11 22 33 44");

            // Create the RtfHeaderFooter with an array containing the Paragraphs to add
            RtfHeaderFooter header = new RtfHeaderFooter(new Element[]{date, address});
            
            // Set the header
            document.setHeader(header);

            // Create the table that will be used as the footer
            Table footer = new Table(2);
            footer.setBorder(0);
            footer.setDefaultCellBorder(0);
            footer.setWidth(100);
            footer.addCell(new Cell("(c) Mark Hall"));
            Paragraph pageNumber = new Paragraph("Page ");
            
            // The RtfPageNumber is an RTF specific element that adds a page number field
            pageNumber.add(new RtfPageNumber());
            pageNumber.setAlignment(Paragraph.ALIGN_RIGHT);
            footer.addCell(new Cell(pageNumber));
            
            // Create the RtfHeaderFooter and set it as the footer to use
            document.setFooter(new RtfHeaderFooter(footer));
            
            document.open();
            
            document.add(new Paragraph("This document has headers and footers created" +
                    " using the RtfHeaderFooter class."));

            document.close();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (DocumentException de) {
            de.printStackTrace();
        }
    }
}