com.lowagie.text.rtf
Class RtfWriter

java.lang.Object
  extended by com.lowagie.text.DocWriter
      extended by com.lowagie.text.rtf.RtfWriter
All Implemented Interfaces:
DocListener, ElementListener, EventListener

Deprecated. The RtfWriter is deprecated and will be removed from the iText library end of 2007

public class RtfWriter
extends DocWriter
implements DocListener

If you are creating a new project using the rtf part of iText, please consider using the new RtfWriter2. The RtfWriter is in bug-fix-only mode, will be deprecated end of 2005 and removed end of 2007. A DocWriter class for Rich Text Files (RTF).

A RtfWriter can be added as a DocListener to a certain Document by getting an instance. Every Element added to the original Document will be written to the OutputStream of this RtfWriter.

Example:

 // creation of the document with a certain size and certain margins
 Document document = new Document(PageSize.A4, 50, 50, 50, 50);
 try {
    // this will write RTF to the Standard OutputStream
    RtfWriter.getInstance(document, System.out);
    // this will write Rtf to a file called text.rtf
    RtfWriter.getInstance(document, new FileOutputStream("text.rtf"));
    // this will write Rtf to for instance the OutputStream of a HttpServletResponse-object
    RtfWriter.getInstance(document, response.getOutputStream());
 }
 catch(DocumentException de) {
    System.err.println(de.getMessage());
 }
 // this will close the document and all the OutputStreams listening to it
 document.close();
 

LIMITATIONS
There are currently still a few limitations on what the RTF Writer can do:


Author:
Mark.Hall@myrealbox.com, Steffen Stundzig, Eric Mattes, Raul Wegmann

Field Summary
static byte[] alignCenter
          Deprecated. Text alignment center tag.
static byte[] alignJustify
          Deprecated. Text alignment justify tag.
static byte[] alignLeft
          Deprecated. Text alignment left tag.
static byte[] alignRight
          Deprecated. Text alignment right tag.
protected static byte bold
          Deprecated. Bold tag.
static byte closeGroup
          Deprecated. This is the character for closing a group.
protected static byte delimiter
          Deprecated. This is the delimiter between RTF tags and normal text.
static byte escape
          Deprecated. This is the escape character which introduces RTF tags.
protected static byte[] field
          Deprecated. Begin field tag
protected static byte[] fieldContent
          Deprecated. Content fo the field
protected static byte[] fieldDisplay
          Deprecated. Last page number (not used)
protected static byte[] fieldHyperlink
          Deprecated. HYPERLINK field
protected static byte[] fieldPage
          Deprecated. PAGE numbers
protected static byte[] fontColor
          Deprecated. Font color tag.
protected static byte fontNumber
          Deprecated. Font number tag.
protected static byte[] fontSize
          Deprecated. Font size tag.
protected static byte italic
          Deprecated. Italic tag.
static byte openGroup
          Deprecated. This is the character for beginning a new group.
static byte[] paragraph
          Deprecated. Begin new paragraph tag.
static byte[] paragraphDefaults
          Deprecated. Reset paragraph defaults tag.
static byte[] sectionPageHeight
          Deprecated. Page height of a section.
static byte[] sectionPageWidth
          Deprecated. Page width of a section.
protected static byte[] strikethrough
          Deprecated. Strikethrough tag.
static double TWIPSFACTOR
          Deprecated. Factor to use when converting.
protected static byte[] underline
          Deprecated. Underline tag.
 
Fields inherited from class com.lowagie.text.DocWriter
closeStream, document, EQUALS, FORWARD, GT, LT, NEWLINE, open, os, pageSize, pause, QUOTE, SPACE, TAB
 
Constructor Summary
protected RtfWriter(Document doc, OutputStream os)
          Deprecated. Constructs a RtfWriter.
 
Method Summary
 boolean add(Element element)
          Deprecated. Signals that an Element was added to the Document.
protected  int addColor(Color newColor)
          Deprecated. Add a new Color to the list of colours.
protected  boolean addElement(Element element, ByteArrayOutputStream out)
          Deprecated. Adds an Element to the Document.
protected  int addFont(Font newFont)
          Deprecated. Add a new Font to the list of fonts.
 void close()
          Deprecated. Signals that the Document was closed and that no other Elements will be added.
static String filterSpecialChar(String str, boolean useHex)
          Deprecated. Replaces special characters with their unicode values
 boolean getGeneratingTOCEntries()
          Deprecated. Gets the current setting of writeTOC
 boolean getHasTitlePage()
          Deprecated. Gets the current setting of hasTitlePage
static RtfWriter getInstance(Document document, OutputStream os)
          Deprecated. Gets an instance of the RtfWriter.
 boolean getLandscape()
          Deprecated. Returns the current landscape setting
 boolean newPage()
          Deprecated. Tells the RtfWriter that a new page is to be begun.
 void open()
          Deprecated. Signals that the Document has been opened and that Elements can be added.
 void resetFooter()
          Deprecated. Resets the footer.
 void resetHeader()
          Deprecated. Resets the header.
 void setFooter(HeaderFooter footer)
          Deprecated. Adds the footer to the bottom of the Document.
 void setGenerateTOCEntries(boolean writeTOC)
          Deprecated. This method controls whether TOC entries are automatically generated
 void setHasTitlePage(boolean hasTitlePage)
          Deprecated. This method controls whether the first page is a title page
 void setHeader(HeaderFooter header)
          Deprecated. Adds the header to the top of the Document.
 void setLandscape(boolean landscape)
          Deprecated. Explicitly sets the page format to use.
 boolean setMarginMirroring(boolean MarginMirroring)
          Deprecated. Parameter that allows you to do margin mirroring (odd/even pages)
 boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
          Deprecated. Sets the page margins
 boolean setPageSize(Rectangle pageSize)
          Deprecated. Sets the page size
protected  void writeFinishingFontSignature(OutputStream out, Chunk chunk)
          Deprecated.  
 void writeHeadersFooters(ByteArrayOutputStream os)
          Deprecated. Write the current header and footer to a ByteArrayOutputStream
protected  void writeInitialFontSignature(OutputStream out, Chunk chunk)
          Deprecated.  
static void writeInt(OutputStream out, int i)
          Deprecated. Write an integer
 boolean writeTOC(String tocTitle, Font titleFont, boolean showTOCasEntry, Font showTOCEntryFont)
          Deprecated. Write the table of contents.
 boolean writingHeaderFooter()
          Deprecated. Returns whether we are currently writing a header or footer
 
Methods inherited from class com.lowagie.text.DocWriter
add, addTabs, clearTextWrap, flush, getISOBytes, hasMarkupAttributes, isCloseStream, pause, removeWatermark, resetPageCount, resume, setCloseStream, setPageCount, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.lowagie.text.DocListener
add, clearTextWrap, removeWatermark, resetPageCount, setPageCount
 

Field Detail

escape

public static final byte escape
Deprecated. 
This is the escape character which introduces RTF tags.

See Also:
Constant Field Values

delimiter

protected static final byte delimiter
Deprecated. 
This is the delimiter between RTF tags and normal text.

See Also:
Constant Field Values

openGroup

public static final byte openGroup
Deprecated. 
This is the character for beginning a new group.

See Also:
Constant Field Values

closeGroup

public static final byte closeGroup
Deprecated. 
This is the character for closing a group.

See Also:
Constant Field Values

fontNumber

protected static final byte fontNumber
Deprecated. 
Font number tag.

See Also:
Constant Field Values

fontSize

protected static final byte[] fontSize
Deprecated. 
Font size tag.


fontColor

protected static final byte[] fontColor
Deprecated. 
Font color tag.


paragraphDefaults

public static final byte[] paragraphDefaults
Deprecated. 
Reset paragraph defaults tag.


paragraph

public static final byte[] paragraph
Deprecated. 
Begin new paragraph tag.


sectionPageWidth

public static final byte[] sectionPageWidth
Deprecated. 
Page width of a section.


sectionPageHeight

public static final byte[] sectionPageHeight
Deprecated. 
Page height of a section.


bold

protected static final byte bold
Deprecated. 
Bold tag.

See Also:
Constant Field Values

italic

protected static final byte italic
Deprecated. 
Italic tag.

See Also:
Constant Field Values

underline

protected static final byte[] underline
Deprecated. 
Underline tag.


strikethrough

protected static final byte[] strikethrough
Deprecated. 
Strikethrough tag.


alignLeft

public static final byte[] alignLeft
Deprecated. 
Text alignment left tag.


alignCenter

public static final byte[] alignCenter
Deprecated. 
Text alignment center tag.


alignRight

public static final byte[] alignRight
Deprecated. 
Text alignment right tag.


alignJustify

public static final byte[] alignJustify
Deprecated. 
Text alignment justify tag.


field

protected static final byte[] field
Deprecated. 
Begin field tag


fieldContent

protected static final byte[] fieldContent
Deprecated. 
Content fo the field


fieldPage

protected static final byte[] fieldPage
Deprecated. 
PAGE numbers


fieldHyperlink

protected static final byte[] fieldHyperlink
Deprecated. 
HYPERLINK field


fieldDisplay

protected static final byte[] fieldDisplay
Deprecated. 
Last page number (not used)


TWIPSFACTOR

public static final double TWIPSFACTOR
Deprecated. 
Factor to use when converting.

See Also:
Constant Field Values
Constructor Detail

RtfWriter

protected RtfWriter(Document doc,
                    OutputStream os)
Deprecated. 
Constructs a RtfWriter.

Parameters:
doc - The Document that is to be written as RTF
os - The OutputStream the writer has to write to.
Method Detail

setGenerateTOCEntries

public void setGenerateTOCEntries(boolean writeTOC)
Deprecated. 
This method controls whether TOC entries are automatically generated

Parameters:
writeTOC - boolean value indicating whether a TOC is to be generated

getGeneratingTOCEntries

public boolean getGeneratingTOCEntries()
Deprecated. 
Gets the current setting of writeTOC

Returns:
boolean value indicating whether a TOC is being generated

setHasTitlePage

public void setHasTitlePage(boolean hasTitlePage)
Deprecated. 
This method controls whether the first page is a title page

Parameters:
hasTitlePage - boolean value indicating whether the first page is a title page

getHasTitlePage

public boolean getHasTitlePage()
Deprecated. 
Gets the current setting of hasTitlePage

Returns:
boolean value indicating whether the first page is a title page

setLandscape

public void setLandscape(boolean landscape)
Deprecated. 
Explicitly sets the page format to use. Otherwise the RtfWriter will try to guess the format by comparing pagewidth and pageheight

Parameters:
landscape - boolean value indicating whether we are using landscape format or not

getLandscape

public boolean getLandscape()
Deprecated. 
Returns the current landscape setting

Returns:
boolean value indicating the current page format

getInstance

public static RtfWriter getInstance(Document document,
                                    OutputStream os)
Deprecated. 
Gets an instance of the RtfWriter.

Parameters:
document - The Document that has to be written
os - The OutputStream the writer has to write to.
Returns:
a new RtfWriter

open

public void open()
Deprecated. 
Signals that the Document has been opened and that Elements can be added.

Specified by:
open in interface DocListener
Overrides:
open in class DocWriter

close

public void close()
Deprecated. 
Signals that the Document was closed and that no other Elements will be added.

The content of the font table, color table, information group, content, header, footer are merged into the final OutputStream

Specified by:
close in interface DocListener
Overrides:
close in class DocWriter

setFooter

public void setFooter(HeaderFooter footer)
Deprecated. 
Adds the footer to the bottom of the Document.

Specified by:
setFooter in interface DocListener
Overrides:
setFooter in class DocWriter
Parameters:
footer -

setHeader

public void setHeader(HeaderFooter header)
Deprecated. 
Adds the header to the top of the Document.

Specified by:
setHeader in interface DocListener
Overrides:
setHeader in class DocWriter
Parameters:
header -

resetFooter

public void resetFooter()
Deprecated. 
Resets the footer.

Specified by:
resetFooter in interface DocListener
Overrides:
resetFooter in class DocWriter

resetHeader

public void resetHeader()
Deprecated. 
Resets the header.

Specified by:
resetHeader in interface DocListener
Overrides:
resetHeader in class DocWriter

newPage

public boolean newPage()
                throws DocumentException
Deprecated. 
Tells the RtfWriter that a new page is to be begun.

Specified by:
newPage in interface DocListener
Overrides:
newPage in class DocWriter
Returns:
true if a new Page was begun.
Throws:
DocumentException - if the Document was not open or had been closed.

setMargins

public boolean setMargins(float marginLeft,
                          float marginRight,
                          float marginTop,
                          float marginBottom)
Deprecated. 
Sets the page margins

Specified by:
setMargins in interface DocListener
Overrides:
setMargins in class DocWriter
Parameters:
marginLeft - The left margin
marginRight - The right margin
marginTop - The top margin
marginBottom - The bottom margin
Returns:
true if the page margins were set.

setPageSize

public boolean setPageSize(Rectangle pageSize)
Deprecated. 
Sets the page size

Specified by:
setPageSize in interface DocListener
Overrides:
setPageSize in class DocWriter
Parameters:
pageSize - A Rectangle specifying the page size
Returns:
true if the page size was set

writeTOC

public boolean writeTOC(String tocTitle,
                        Font titleFont,
                        boolean showTOCasEntry,
                        Font showTOCEntryFont)
Deprecated. 
Write the table of contents.

Parameters:
tocTitle - The title that will be displayed above the TOC
titleFont - The Font that will be used for the tocTitle
showTOCasEntry - Set this to true if you want the TOC to appear as an entry in the TOC
showTOCEntryFont - Use this Font to specify what Font to use when showTOCasEntry is true
Returns:
true if the TOC was added.

add

public boolean add(Element element)
            throws DocumentException
Deprecated. 
Signals that an Element was added to the Document.

Specified by:
add in interface ElementListener
Overrides:
add in class DocWriter
Parameters:
element - A high level object to add
Returns:
true if the element was added, false if not.
Throws:
DocumentException - if a document isn't open yet, or has been closed

addElement

protected boolean addElement(Element element,
                             ByteArrayOutputStream out)
                      throws DocumentException
Deprecated. 
Adds an Element to the Document.

Parameters:
element - the high level element to add
out - the outputstream to which the RTF data is sent
Returns:
true if the element was added, false if not.
Throws:
DocumentException - if a document isn't open yet, or has been closed

writeInitialFontSignature

protected void writeInitialFontSignature(OutputStream out,
                                         Chunk chunk)
                                  throws IOException
Deprecated. 
Throws:
IOException

writeFinishingFontSignature

protected void writeFinishingFontSignature(OutputStream out,
                                           Chunk chunk)
                                    throws IOException
Deprecated. 
Throws:
IOException

addFont

protected int addFont(Font newFont)
Deprecated. 
Add a new Font to the list of fonts. If the Font already exists in the list of fonts, then it is not added again.

Parameters:
newFont - The Font to be added
Returns:
The index of the Font in the font list

addColor

protected int addColor(Color newColor)
Deprecated. 
Add a new Color to the list of colours. If the Color already exists in the list of colours, then it is not added again.

Parameters:
newColor - The Color to be added
Returns:
The index of the color in the colour list

writeInt

public static final void writeInt(OutputStream out,
                                  int i)
                           throws IOException
Deprecated. 
Write an integer

Parameters:
out - The OuputStream to which the int value is to be written
i - The int value to be written
Throws:
IOException

writeHeadersFooters

public void writeHeadersFooters(ByteArrayOutputStream os)
                         throws IOException
Deprecated. 
Write the current header and footer to a ByteArrayOutputStream

Parameters:
os - The ByteArrayOutputStream to which the header and footer will be written.
Throws:
IOException

writingHeaderFooter

public boolean writingHeaderFooter()
Deprecated. 
Returns whether we are currently writing a header or footer

Returns:
the value of inHeaderFooter

filterSpecialChar

public static final String filterSpecialChar(String str,
                                             boolean useHex)
Deprecated. 
Replaces special characters with their unicode values

Parameters:
str - The original String
useHex -
Returns:
The converted String

setMarginMirroring

public boolean setMarginMirroring(boolean MarginMirroring)
Deprecated. 
Description copied from interface: DocListener
Parameter that allows you to do margin mirroring (odd/even pages)

Specified by:
setMarginMirroring in interface DocListener
Overrides:
setMarginMirroring in class DocWriter
Returns:
true if succesfull
See Also:
DocListener.setMarginMirroring(boolean)


Copyright © 2006-2007 EGIZ - E-Government Innovationszentrum. All Rights Reserved.