> -----Original Message-----
> From: Jose Hurtado [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, May 12, 2005 3:48 PM
> To: Paulo Soares
> Subject: iText - RtfTotalPageNumber class
> 
> I develop this.. maybe can be useful for iText.
> 
> How-to use:
> 
>         Document document = new Document(PageSize.A4);
>         RtfWriter2 rtf = RtfWriter2.getInstance(document,
>                                               new 
> FileOutputStream(filename));
> 
>         /* Define Fonts */
>         Font fontHeader = new Font(Font.HELVETICA, 11, Font.BOLD);
> 
>         /* Open the document to begin insert data */
>   g      document.open();
> 
>         Paragraph paraHeader = new Paragraph();
>         paraHeader.add(new Phrase("Paes ", fontHeader));
>         paraHeader.add(new RtfPageNumber(fontHeader));
>         paraHeader.add(new Phrase(" of ", fontHeader));
>         paraHeader.add(new RtfTotalPageNumber(fontHeader));
>         paraHeader.add(new Phrase(" to ", fontHeader));
> 
>         HeaderFooter header = new RtfHeaderFooter(paraHeader);
>         document.setHeader(header);
> 
>         for(int i=0;i<200;i++) {
>             document.add(new Paragraph(""));
>         }
> 
>         document.close();
> 
> 
> Great work with iText :)
> 
> Best Regards
> Jose Hurtado
> 
> 
> 
/*
 * Created on Aug 10, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.lowagie.text.rtf.field;

import java.io.IOException;

import com.lowagie.text.Font;
import com.lowagie.text.rtf.document.RtfDocument;
import com.lowagie.text.rtf.field.RtfField;


/**
 * The RtfPageNumber provides the page number field in rtf documents.
 * 
 * @version $Version:$
 * @author Jose Hurtado <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
 */
public class RtfTotalPageNumber extends RtfField {

    /**
     * Constructs a RtfPageNumber. This can be added anywhere to add a page number field.
     */
    public RtfTotalPageNumber() {
        super(null);
    }
    
    /**
     * Constructs a RtfPageNumber with a specified Font. This can be added anywhere to
     * add a page number field.
     * @param font
     */
    public RtfTotalPageNumber(Font font) {
        super(null, font);
    }
    
    /**
     * Constructs a RtfPageNumber object.
     * 
     * @param doc The RtfDocument this RtfPageNumber belongs to
     */
    public RtfTotalPageNumber(RtfDocument doc) {
        super(doc);
    }
    
    /**
     * Constructs a RtfPageNumber object with a specific font.
     * 
     * @param doc The RtfDocument this RtfPageNumber belongs to
     * @param font The Font to use
     */
    public RtfTotalPageNumber(RtfDocument doc, Font font) {
        super(doc, font);
    }
    
    /**
     * Writes the field NUMPAGES instruction with Arabic format
     * 
     * @return A byte array containing "PAGE"
     * @throws IOException
     */
    protected byte[] writeFieldInstContent() throws IOException {
        return "NUMPAGES \\\\* Arabic".getBytes();
    }

    /**
     * Writes the field result content
     * 
     * @return An empty byte array
     * @throws IOException
     */
    protected byte[] writeFieldResultContent() throws IOException {
        //return new byte[0];
        return "1".getBytes();
    }
}

Reply via email to