com.lowagie.text.rtf
Class RtfWriter

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

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
          Text alignment center tag.
static byte[] alignJustify
          Text alignment justify tag.
static byte[] alignLeft
          Text alignment left tag.
static byte[] alignRight
          Text alignment right tag.
private static byte[] annotation
          Annotation text tag.
private static byte[] annotationAuthor
          Annotation Author tag.
private static byte[] annotationID
          Annotation ID tag.
private static byte[] ansi
          RTF encoding.
private static byte[] ansiCodepage
          RTF encoding codepage.
protected static byte bold
          Bold tag.
static byte closeGroup
          This is the character for closing a group.
private static byte[] colorBlue
          Blue value tag.
private static byte[] colorGreen
          Green value tag.
private  ArrayList colorList
          This ArrayList contains all colours used in the document.
private static byte[] colorRed
          Red value tag.
private static byte[] colorTable
          Begin colour table tag.
private static byte commaDelimiter
          This is another delimiter between RTF tags and normal text.
private  ByteArrayOutputStream content
          This ByteArrayOutputStream contains the main body of the document.
private  int currentListID
          Current list ID.
private static byte[] day
          Day tag.
private static byte[] defaultFont
          Default Font.
protected static byte delimiter
          This is the delimiter between RTF tags and normal text.
private static byte[] docBegin
          RTF begin and version.
private static byte[] endSuperSub
          End super/sub script.
static byte escape
          This is the escape character which introduces RTF tags.
private static byte[] extendedEscape
          This is another escape character which introduces RTF tags.
private static byte[] facingPages
          Facing pages tag
protected static byte[] field
          Begin field tag
protected static byte[] fieldContent
          Content fo the field
protected static byte[] fieldDisplay
          Last page number (not used)
protected static byte[] fieldHyperlink
          HYPERLINK field
protected static byte[] fieldPage
          PAGE numbers
private static byte[] firstIndent
          First indent tag.
private static byte[] fontArial
          Font Arial tag.
private static byte[] fontCharset
          Font charset tag.
protected static byte[] fontColor
          Font color tag.
private static byte[] fontCourier
          Font Courier tag.
private  ArrayList fontList
          This ArrayList contains all fonts used in the document.
private static byte[] fontModern
          Modern font tag.
protected static byte fontNumber
          Font number tag.
private static byte[] fontRoman
          Roman font tag.
protected static byte[] fontSize
          Font size tag.
private static byte[] fontSwiss
          Swiss font tag.
private static byte[] fontSymbol
          Font Symbol tag.
private static byte[] fontTable
          Begin the font table tag.
private static byte[] fontTech
          Tech font tag.
private static byte[] fontTimesNewRoman
          Font Times New Roman tag.
private static byte[] fontWindings
          Font Windings tag.
private  HeaderFooter footer
          Document footer.
private static byte[] footerBegin
          Begin footer group tag.
private static byte[] footerfBegin
           
private static byte[] footerlBegin
           
private static byte[] footerrBegin
           
private  boolean hasTitlePage
          Special title page
private  HeaderFooter header
          Document header.
private static byte[] headerBegin
          Begin header group tag.
private static byte[] headerfBegin
           
private static byte[] headerlBegin
           
private static byte[] headerrBegin
           
private static byte[] hour
          Hour tag.
private static byte[] hybridList
          RTF Writer outputs hybrid lists
private  ByteArrayOutputStream info
          This ByteArrayOutputStream contains the information group.
private static byte[] infoBegin
          Begin the info group tag.
private  boolean inHeaderFooter
          Currently writing either Header or Footer
private  boolean inTable
          Currently writing a Table
protected static byte italic
          Italic tag.
private  boolean landscape
          Landscape or Portrait Document
private static byte[] landscapeTag1
          Document Landscape tag 1.
private static byte[] landscapeTag2
          Document Landscape tag 2.
private static byte[] listBegin
          Actual list begin
private static byte[] listBulletOld
          Old Bullet Style
private static byte[] listCurrentLevel
          Current list level
private static byte[] listDefinition
          Begin a List definition
private static byte[] listID
          Current List ID
private  ArrayList listIds
          List of current Lists.
private static byte[] listIndent
          Left indent tag.
private  int listLevel
          Current List Level.
private static byte[] listLevelAlignNew
          Level alignment (new)
private static byte[] listLevelAlignOld
          Level alignment (old)
private static byte[] listLevelDefinition
          Current List level
private static byte[] listLevelNumbers
          Filler for Level Numbers
private static byte[] listLevelNumbersDefinition
          Level Numbers Definition
private static byte[] listLevelStartAt
          Level starting number
private static byte[] listLevelTextDefinition
          Level text group
private static byte[] listLevelTextLength
          Filler for Level Text Length
private static byte[] listLevelTextStyleBullet
          Level Text Bullet Style
private static byte[] listLevelTextStyleNumbers
          Level Text Numbering Style
private static byte[] listLevelTypeNew
          Level numbering (new)
private static byte[] listLevelTypeOld
          Level numbering (old)
private  ByteArrayOutputStream listoverride
          This ByteArrayOutputStream contains the list override table.
private static byte[] listOverride
          List override
private static byte[] listOverrideCount
          Number of overrides
private static byte[] listoverridetableGroup
          Begin the List Override Table
private  ByteArrayOutputStream listtable
          This ByteArrayOutputStream contains the list table.
private static byte[] listtableGroup
          Begin the List Table
private static byte[] listTemplateID
          List Template ID
private static byte[] listTextOld
          List text group for older browsers
private  int marginBottom
          Bottom margin.
private  int marginLeft
          Left margin.
private  int marginRight
          Right margin.
private  int marginTop
          Top margin.
private  int maxListLevel
          Current maximum List Level.
private static byte[] metaAuthor
          Author tag.
private static byte[] metaCreationDate
          Creation Date tag.
private static byte[] metaKeywords
          Keywords tag.
private static byte[] metaProducer
          Producer tag.
private static byte[] metaSubject
          Subject tag.
private static byte[] metaTitle
          Title tag.
private static byte[] minute
          Minute tag.
private static byte[] month
          Month tag.
private static byte[] newPage
          New Page tag.
static byte openGroup
          This is the character for beginning a new group.
private  int pageHeight
          Page height.
private  int pageWidth
          Page width.
static byte[] paragraph
          Begin new paragraph tag.
static byte[] paragraphDefaults
          Reset paragraph defaults tag.
private static byte[] picture
          Begin the picture tag
private static byte[] pictureBMP
          BMP Image
private static byte[] pictureGroup
          Begin the main Picture group tag
private static byte[] pictureHeight
          Picture height
private static byte[] pictureJPEG
          JPEG Image
private static byte[] picturePNG
          PNG Image
private static byte[] pictureScaleX
          Picture scale horizontal percent
private static byte[] pictureScaleY
          Picture scale vertical percent
private static byte[] pictureWidth
          Picture width
private static byte[] pictureWMF
          WMF Image
private static byte[] rightIndent
          Right indent tag.
private static byte[] rtfMarginBottom
          Margin bottom tag.
private static byte[] rtfMarginLeft
          Margin left tag.
private static byte[] rtfMarginRight
          Margin right tag.
private static byte[] rtfMarginTop
          Margin top tag.
private static byte[] rtfPaperHeight
          Paper height tag.
private static byte[] rtfPaperWidth
          Paper width tag.
private static byte[] second
          Second tag.
private static byte[] section
          Begin new section tag.
private static byte[] sectionDefaults
          Reset section defaults tag.
static byte[] sectionPageHeight
          Page height of a section.
static byte[] sectionPageWidth
          Page width of a section.
private static byte[] startSub
          Start subscript.
private static byte[] startSuper
          Start superscript.
protected static byte[] strikethrough
          Strikethrough tag.
private static byte[] tab
          Tab
private static byte[] tabStop
          Tab Stop
private static byte[] titlePage
          Title Page tag
static double TWIPSFACTOR
          Factor to use when converting.
protected static byte[] underline
          Underline tag.
private  boolean writeTOC
          Write a TOC
private static byte[] year
          Year 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)
          Constructs a RtfWriter.
 
Method Summary
 boolean add(Element element)
          Signals that an Element was added to the Document.
protected  int addColor(Color newColor)
          Add a new Color to the list of colours.
protected  boolean addElement(Element element, ByteArrayOutputStream out)
          Adds an Element to the Document.
protected  int addFont(Font newFont)
          Add a new Font to the list of fonts.
private  void addHeaderFooterFontColor(HeaderFooter hf)
           
 void close()
          Signals that the Document was closed and that no other Elements will be added.
static String filterSpecialChar(String str, boolean useHex)
          Replaces special characters with their unicode values
 boolean getGeneratingTOCEntries()
          Gets the current setting of writeTOC
 boolean getHasTitlePage()
          Gets the current setting of hasTitlePage
static RtfWriter getInstance(Document document, OutputStream os)
          Gets an instance of the RtfWriter.
 boolean getLandscape()
          Returns the current landscape setting
private  int getRandomInt()
          Get a random integer.
private  void initDefaults()
          Initialise all helper classes.
 boolean newPage()
          Tells the RtfWriter that a new page is to be begun.
 void open()
          Signals that the Document has been opened and that Elements can be added.
private  boolean parseFormat(Rectangle pageSize, boolean rotate)
          This method tries to fit the Rectangle pageSize to one of the predefined PageSize rectangles.
private  void processHeaderFooter(HeaderFooter hf)
           
private  boolean rectEquals(Rectangle rect1, Rectangle rect2)
          This method compares to Rectangles.
 void resetFooter()
          Resets the footer.
 void resetHeader()
          Resets the header.
 void setFooter(HeaderFooter footer)
          Adds the footer to the bottom of the Document.
 void setGenerateTOCEntries(boolean writeTOC)
          This method controls whether TOC entries are automatically generated
 void setHasTitlePage(boolean hasTitlePage)
          This method controls whether the first page is a title page
 void setHeader(HeaderFooter header)
          Adds the header to the top of the Document.
 void setLandscape(boolean landscape)
          Explicitly sets the page format to use.
 boolean setMarginMirroring(boolean MarginMirroring)
          Parameter that allows you to do margin mirroring (odd/even pages)
 boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
          Sets the page margins
 boolean setPageSize(Rectangle pageSize)
          Sets the page size
private  void writeAnchor(Anchor anchor, ByteArrayOutputStream out)
          Write an Anchor.
private  void writeAnnotation(Annotation annotationElement, ByteArrayOutputStream out)
          Write an Annotation
private  void writeChunk(Chunk chunk, ByteArrayOutputStream out)
          Write a Chunk and all its font properties.
private  void writeColorList()
          Write the colour list to the final ByteArrayOutputStream
private  boolean writeDocument()
          Merge all the different ArrayLists and ByteArrayOutputStreams to the final ByteArrayOutputStream
private  void writeDocumentFormat()
          Write the Document's Paper and Margin Size to the final ByteArrayOutputStream
private  void writeDocumentIntro()
          Write the Rich Text file settings
protected  void writeFinishingFontSignature(OutputStream out, Chunk chunk)
           
private  void writeFontList()
          Write the font list to the final ByteArrayOutputStream
private  void writeFormatedDateTime(String date)
          Writes a date.
private  void writeHeaderFooter(HeaderFooter headerFooter, byte[] hfType, ByteArrayOutputStream target)
          Write a HeaderFooter to a ByteArrayOutputStream
 void writeHeadersFooters(ByteArrayOutputStream os)
          Write the current header and footer to a ByteArrayOutputStream
private  void writeImage(Image image, ByteArrayOutputStream out)
          Write an Image.
private  void writeInfoGroup()
          Write the Information Group to the final ByteArrayOutputStream
protected  void writeInitialFontSignature(OutputStream out, Chunk chunk)
           
static void writeInt(OutputStream out, int i)
          Write an integer
private  void writeList()
          Write the listtable and listoverridetable to the final ByteArrayOutputStream
private  void writeList(List list, ByteArrayOutputStream out)
          Write a List
private  void writeListElement(ListItem listItem, ByteArrayOutputStream out)
          Write a ListItem
private  void writeMeta(byte[] metaName, Meta meta)
          Add a Meta element.
private  void writeParagraph(Paragraph paragraphElement, ByteArrayOutputStream out)
          Write the beginning of a new Paragraph
private  void writePhrase(Phrase phrase, ByteArrayOutputStream out)
          Write a Phrase.
private  void writeSection(Section sectionElement, ByteArrayOutputStream out)
          Write the beginning of a new Section
private  void writeSectionDefaults(ByteArrayOutputStream out)
          Writes the default values for the current Section
private  void writeTable(Table table, ByteArrayOutputStream out)
          Write a Table.
 boolean writeTOC(String tocTitle, Font titleFont, boolean showTOCasEntry, Font showTOCEntryFont)
          Write the table of contents.
 boolean writingHeaderFooter()
          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
This is the escape character which introduces RTF tags.

See Also:
Constant Field Values

extendedEscape

private static final byte[] extendedEscape
This is another escape character which introduces RTF tags.


delimiter

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

See Also:
Constant Field Values

commaDelimiter

private static final byte commaDelimiter
This is another delimiter between RTF tags and normal text.

See Also:
Constant Field Values

openGroup

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

See Also:
Constant Field Values

closeGroup

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

See Also:
Constant Field Values

docBegin

private static final byte[] docBegin
RTF begin and version.


ansi

private static final byte[] ansi
RTF encoding.


ansiCodepage

private static final byte[] ansiCodepage
RTF encoding codepage.


fontTable

private static final byte[] fontTable
Begin the font table tag.


fontNumber

protected static final byte fontNumber
Font number tag.

See Also:
Constant Field Values

fontSize

protected static final byte[] fontSize
Font size tag.


fontColor

protected static final byte[] fontColor
Font color tag.


fontModern

private static final byte[] fontModern
Modern font tag.


fontSwiss

private static final byte[] fontSwiss
Swiss font tag.


fontRoman

private static final byte[] fontRoman
Roman font tag.


fontTech

private static final byte[] fontTech
Tech font tag.


fontCharset

private static final byte[] fontCharset
Font charset tag.


fontCourier

private static final byte[] fontCourier
Font Courier tag.


fontArial

private static final byte[] fontArial
Font Arial tag.


fontSymbol

private static final byte[] fontSymbol
Font Symbol tag.


fontTimesNewRoman

private static final byte[] fontTimesNewRoman
Font Times New Roman tag.


fontWindings

private static final byte[] fontWindings
Font Windings tag.


defaultFont

private static final byte[] defaultFont
Default Font.


firstIndent

private static final byte[] firstIndent
First indent tag.


listIndent

private static final byte[] listIndent
Left indent tag.


rightIndent

private static final byte[] rightIndent
Right indent tag.


sectionDefaults

private static final byte[] sectionDefaults
Reset section defaults tag.


section

private static final byte[] section
Begin new section tag.


paragraphDefaults

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


paragraph

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


sectionPageWidth

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


sectionPageHeight

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


listtableGroup

private static final byte[] listtableGroup
Begin the List Table


listoverridetableGroup

private static final byte[] listoverridetableGroup
Begin the List Override Table


listDefinition

private static final byte[] listDefinition
Begin a List definition


listTemplateID

private static final byte[] listTemplateID
List Template ID


hybridList

private static final byte[] hybridList
RTF Writer outputs hybrid lists


listLevelDefinition

private static final byte[] listLevelDefinition
Current List level


listLevelTypeOld

private static final byte[] listLevelTypeOld
Level numbering (old)


listLevelTypeNew

private static final byte[] listLevelTypeNew
Level numbering (new)


listLevelAlignOld

private static final byte[] listLevelAlignOld
Level alignment (old)


listLevelAlignNew

private static final byte[] listLevelAlignNew
Level alignment (new)


listLevelStartAt

private static final byte[] listLevelStartAt
Level starting number


listLevelTextDefinition

private static final byte[] listLevelTextDefinition
Level text group


listLevelTextLength

private static final byte[] listLevelTextLength
Filler for Level Text Length


listLevelTextStyleNumbers

private static final byte[] listLevelTextStyleNumbers
Level Text Numbering Style


listLevelTextStyleBullet

private static final byte[] listLevelTextStyleBullet
Level Text Bullet Style


listLevelNumbersDefinition

private static final byte[] listLevelNumbersDefinition
Level Numbers Definition


listLevelNumbers

private static final byte[] listLevelNumbers
Filler for Level Numbers


tabStop

private static final byte[] tabStop
Tab Stop


listBegin

private static final byte[] listBegin
Actual list begin


listCurrentLevel

private static final byte[] listCurrentLevel
Current list level


listTextOld

private static final byte[] listTextOld
List text group for older browsers


tab

private static final byte[] tab
Tab


listBulletOld

private static final byte[] listBulletOld
Old Bullet Style


listID

private static final byte[] listID
Current List ID


listOverride

private static final byte[] listOverride
List override


listOverrideCount

private static final byte[] listOverrideCount
Number of overrides


bold

protected static final byte bold
Bold tag.

See Also:
Constant Field Values

italic

protected static final byte italic
Italic tag.

See Also:
Constant Field Values

underline

protected static final byte[] underline
Underline tag.


strikethrough

protected static final byte[] strikethrough
Strikethrough tag.


alignLeft

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


alignCenter

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


alignRight

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


alignJustify

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


colorTable

private static final byte[] colorTable
Begin colour table tag.


colorRed

private static final byte[] colorRed
Red value tag.


colorGreen

private static final byte[] colorGreen
Green value tag.


colorBlue

private static final byte[] colorBlue
Blue value tag.


infoBegin

private static final byte[] infoBegin
Begin the info group tag.


metaAuthor

private static final byte[] metaAuthor
Author tag.


metaSubject

private static final byte[] metaSubject
Subject tag.


metaKeywords

private static final byte[] metaKeywords
Keywords tag.


metaTitle

private static final byte[] metaTitle
Title tag.


metaProducer

private static final byte[] metaProducer
Producer tag.


metaCreationDate

private static final byte[] metaCreationDate
Creation Date tag.


year

private static final byte[] year
Year tag.


month

private static final byte[] month
Month tag.


day

private static final byte[] day
Day tag.


hour

private static final byte[] hour
Hour tag.


minute

private static final byte[] minute
Minute tag.


second

private static final byte[] second
Second tag.


startSuper

private static final byte[] startSuper
Start superscript.


startSub

private static final byte[] startSub
Start subscript.


endSuperSub

private static final byte[] endSuperSub
End super/sub script.


titlePage

private static final byte[] titlePage
Title Page tag


facingPages

private static final byte[] facingPages
Facing pages tag


headerBegin

private static final byte[] headerBegin
Begin header group tag.


footerBegin

private static final byte[] footerBegin
Begin footer group tag.


headerlBegin

private static final byte[] headerlBegin

footerlBegin

private static final byte[] footerlBegin

headerrBegin

private static final byte[] headerrBegin

footerrBegin

private static final byte[] footerrBegin

headerfBegin

private static final byte[] headerfBegin

footerfBegin

private static final byte[] footerfBegin

rtfPaperWidth

private static final byte[] rtfPaperWidth
Paper width tag.


rtfPaperHeight

private static final byte[] rtfPaperHeight
Paper height tag.


rtfMarginLeft

private static final byte[] rtfMarginLeft
Margin left tag.


rtfMarginRight

private static final byte[] rtfMarginRight
Margin right tag.


rtfMarginTop

private static final byte[] rtfMarginTop
Margin top tag.


rtfMarginBottom

private static final byte[] rtfMarginBottom
Margin bottom tag.


newPage

private static final byte[] newPage
New Page tag.


landscapeTag1

private static final byte[] landscapeTag1
Document Landscape tag 1.


landscapeTag2

private static final byte[] landscapeTag2
Document Landscape tag 2.


annotationID

private static final byte[] annotationID
Annotation ID tag.


annotationAuthor

private static final byte[] annotationAuthor
Annotation Author tag.


annotation

private static final byte[] annotation
Annotation text tag.


pictureGroup

private static final byte[] pictureGroup
Begin the main Picture group tag


picture

private static final byte[] picture
Begin the picture tag


picturePNG

private static final byte[] picturePNG
PNG Image


pictureJPEG

private static final byte[] pictureJPEG
JPEG Image


pictureBMP

private static final byte[] pictureBMP
BMP Image


pictureWMF

private static final byte[] pictureWMF
WMF Image


pictureWidth

private static final byte[] pictureWidth
Picture width


pictureHeight

private static final byte[] pictureHeight
Picture height


pictureScaleX

private static final byte[] pictureScaleX
Picture scale horizontal percent


pictureScaleY

private static final byte[] pictureScaleY
Picture scale vertical percent


field

protected static final byte[] field
Begin field tag


fieldContent

protected static final byte[] fieldContent
Content fo the field


fieldPage

protected static final byte[] fieldPage
PAGE numbers


fieldHyperlink

protected static final byte[] fieldHyperlink
HYPERLINK field


fieldDisplay

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


fontList

private ArrayList fontList
This ArrayList contains all fonts used in the document.


colorList

private ArrayList colorList
This ArrayList contains all colours used in the document.


content

private ByteArrayOutputStream content
This ByteArrayOutputStream contains the main body of the document.


info

private ByteArrayOutputStream info
This ByteArrayOutputStream contains the information group.


listtable

private ByteArrayOutputStream listtable
This ByteArrayOutputStream contains the list table.


listoverride

private ByteArrayOutputStream listoverride
This ByteArrayOutputStream contains the list override table.


header

private HeaderFooter header
Document header.


footer

private HeaderFooter footer
Document footer.


marginLeft

private int marginLeft
Left margin.


marginRight

private int marginRight
Right margin.


marginTop

private int marginTop
Top margin.


marginBottom

private int marginBottom
Bottom margin.


pageWidth

private int pageWidth
Page width.


pageHeight

private int pageHeight
Page height.


TWIPSFACTOR

public static final double TWIPSFACTOR
Factor to use when converting.

See Also:
Constant Field Values

currentListID

private int currentListID
Current list ID.


listIds

private ArrayList listIds
List of current Lists.


listLevel

private int listLevel
Current List Level.


maxListLevel

private int maxListLevel
Current maximum List Level.


writeTOC

private boolean writeTOC
Write a TOC


hasTitlePage

private boolean hasTitlePage
Special title page


inHeaderFooter

private boolean inHeaderFooter
Currently writing either Header or Footer


inTable

private boolean inTable
Currently writing a Table


landscape

private boolean landscape
Landscape or Portrait Document

Constructor Detail

RtfWriter

protected RtfWriter(Document doc,
                    OutputStream os)
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)
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()
Gets the current setting of writeTOC

Returns:
boolean value indicating whether a TOC is being generated

setHasTitlePage

public void setHasTitlePage(boolean hasTitlePage)
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()
Gets the current setting of hasTitlePage

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

setLandscape

public void setLandscape(boolean landscape)
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()
Returns the current landscape setting

Returns:
boolean value indicating the current page format

getInstance

public static RtfWriter getInstance(Document document,
                                    OutputStream os)
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()
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()
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)
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)
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()
Resets the footer.

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

resetHeader

public void resetHeader()
Resets the header.

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

newPage

public boolean newPage()
                throws DocumentException
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)
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)
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)
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
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
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

writeSection

private void writeSection(Section sectionElement,
                          ByteArrayOutputStream out)
                   throws IOException,
                          DocumentException
Write the beginning of a new Section

Parameters:
sectionElement - The Section be written
out - The ByteArrayOutputStream to write to
Throws:
IOException
DocumentException

writeParagraph

private void writeParagraph(Paragraph paragraphElement,
                            ByteArrayOutputStream out)
                     throws IOException
Write the beginning of a new Paragraph

Parameters:
paragraphElement - The Paragraph to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException

writePhrase

private void writePhrase(Phrase phrase,
                         ByteArrayOutputStream out)
                  throws IOException
Write a Phrase.

Parameters:
phrase - The Phrase item to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException

writeAnchor

private void writeAnchor(Anchor anchor,
                         ByteArrayOutputStream out)
                  throws IOException
Write an Anchor. Anchors are treated like Phrases.

Parameters:
anchor - The Chunk item to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException

writeChunk

private void writeChunk(Chunk chunk,
                        ByteArrayOutputStream out)
                 throws IOException,
                        DocumentException
Write a Chunk and all its font properties.

Parameters:
chunk - The Chunk item to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException
DocumentException

writeInitialFontSignature

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

writeFinishingFontSignature

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

writeListElement

private void writeListElement(ListItem listItem,
                              ByteArrayOutputStream out)
                       throws IOException,
                              DocumentException
Write a ListItem

Parameters:
listItem - The ListItem to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException
DocumentException

writeList

private void writeList(List list,
                       ByteArrayOutputStream out)
                throws IOException,
                       DocumentException
Write a List

Parameters:
list - The List to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException
DocumentException

writeTable

private void writeTable(Table table,
                        ByteArrayOutputStream out)
                 throws IOException,
                        DocumentException
Write a Table.

Parameters:
table - The table to be written
out - The ByteArrayOutputStream to write to Currently no nesting of tables is supported. If a cell contains anything but a Cell Object it is ignored.
Throws:
IOException
DocumentException

writeImage

private void writeImage(Image image,
                        ByteArrayOutputStream out)
                 throws IOException,
                        DocumentException
Write an Image.

Parameters:
image - The image to be written
out - The ByteArrayOutputStream to write to At the moment only PNG and JPEG Images are supported.
Throws:
IOException
DocumentException

writeAnnotation

private void writeAnnotation(Annotation annotationElement,
                             ByteArrayOutputStream out)
                      throws IOException
Write an Annotation

Parameters:
annotationElement - The Annotation to be written
out - The ByteArrayOutputStream to write to
Throws:
IOException

writeMeta

private void writeMeta(byte[] metaName,
                       Meta meta)
                throws IOException
Add a Meta element. It is written to the Inforamtion Group and merged with the main ByteArrayOutputStream when the Document is closed.

Parameters:
metaName - The type of Meta element to be added
meta - The Meta element to be added Currently only the Meta Elements Author, Subject, Keywords, Title, Producer and CreationDate are supported.
Throws:
IOException

writeFormatedDateTime

private void writeFormatedDateTime(String date)
                            throws IOException
Writes a date. The date is formated Year, Month, Day, Hour, Minute, Second

Parameters:
date - The date to be written
Throws:
IOException

addFont

protected int addFont(Font newFont)
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)
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

writeDocument

private boolean writeDocument()
Merge all the different ArrayLists and ByteArrayOutputStreams to the final ByteArrayOutputStream

Returns:
true if all information was sucessfully written to the ByteArrayOutputStream

writeDocumentIntro

private void writeDocumentIntro()
                         throws IOException
Write the Rich Text file settings

Throws:
IOException

writeFontList

private void writeFontList()
                    throws IOException
Write the font list to the final ByteArrayOutputStream

Throws:
IOException

writeColorList

private void writeColorList()
                     throws IOException
Write the colour list to the final ByteArrayOutputStream

Throws:
IOException

writeInfoGroup

private void writeInfoGroup()
                     throws IOException
Write the Information Group to the final ByteArrayOutputStream

Throws:
IOException

writeList

private void writeList()
                throws IOException
Write the listtable and listoverridetable to the final ByteArrayOutputStream

Throws:
IOException

writeInt

public static final void writeInt(OutputStream out,
                                  int i)
                           throws IOException
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

getRandomInt

private int getRandomInt()
Get a random integer. This returns a unique random integer to be used with listids.

Returns:
Random int value.

writeHeadersFooters

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

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

writeHeaderFooter

private void writeHeaderFooter(HeaderFooter headerFooter,
                               byte[] hfType,
                               ByteArrayOutputStream target)
                        throws IOException
Write a HeaderFooter to a ByteArrayOutputStream

Parameters:
headerFooter - The HeaderFooter object to be written.
hfType - The type of header or footer to be added.
target - The ByteArrayOutputStream to which the HeaderFooter will be written.
Throws:
IOException

writeDocumentFormat

private void writeDocumentFormat()
                          throws IOException
Write the Document's Paper and Margin Size to the final ByteArrayOutputStream

Throws:
IOException

initDefaults

private void initDefaults()
Initialise all helper classes. Clears alls lists, creates new ByteArrayOutputStream's


writeSectionDefaults

private void writeSectionDefaults(ByteArrayOutputStream out)
                           throws IOException
Writes the default values for the current Section

Parameters:
out - The ByteArrayOutputStream to be written to
Throws:
IOException

parseFormat

private boolean parseFormat(Rectangle pageSize,
                            boolean rotate)
This method tries to fit the Rectangle pageSize to one of the predefined PageSize rectangles. If a match is found the pageWidth and pageHeight will be set according to values determined from files generated by MS Word2000 and OpenOffice 641. If no match is found the method will try to match the rotated Rectangle by calling itself with the parameter rotate set to true.

Parameters:
pageSize - a rectangle defining the size of the page
rotate - portrait or lanscape?
Returns:
true if the format parsing succeeded

rectEquals

private boolean rectEquals(Rectangle rect1,
                           Rectangle rect2)
This method compares to Rectangles. They are considered equal if width and height are the same

Parameters:
rect1 -
rect2 -
Returns:
true if rect1 and rect2 represent the same rectangle

writingHeaderFooter

public boolean writingHeaderFooter()
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)
Replaces special characters with their unicode values

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

addHeaderFooterFontColor

private void addHeaderFooterFontColor(HeaderFooter hf)

processHeaderFooter

private void processHeaderFooter(HeaderFooter hf)

setMarginMirroring

public boolean setMarginMirroring(boolean MarginMirroring)
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
See Also:
DocListener.setMarginMirroring(boolean)