com.lowagie.text.rtf

Class RtfWriter

public class RtfWriter extends DocWriter

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

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 (mhall@edu.uni-klu.ac.at) Steffen Stundzig (Steffen.Stundzig@smb-tec.com) Eric Mattes (ericmattes@yahoo.com) Raul Wegmann (raul.wegmann@uam.es)

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.
static byte[]annotation
Annotation text tag.
static byte[]annotationAuthor
Annotation Author tag.
static byte[]annotationID
Annotation ID tag.
static byte[]ansi
RTF encoding.
static byte[]ansiCodepage
RTF encoding codepage.
protected static bytebold
Bold tag.
static bytecloseGroup
This is the character for closing a group.
static byte[]colorBlue
Blue value tag.
static byte[]colorGreen
Green value tag.
ArrayListcolorList
This ArrayList contains all colours used in the document.
static byte[]colorRed
Red value tag.
static byte[]colorTable
Begin colour table tag.
static bytecommaDelimiter
This is another delimiter between RTF tags and normal text.
ByteArrayOutputStreamcontent
This ByteArrayOutputStream contains the main body of the document.
intcurrentListID
Current list ID.
static byte[]day
Day tag.
static byte[]defaultFont
Default Font.
protected static bytedelimiter
This is the delimiter between RTF tags and normal text.
static byte[]docBegin
RTF begin and version.
static byte[]endSuperSub
End super/sub script.
static byteescape
This is the escape character which introduces RTF tags.
static byte[]extendedEscape
This is another escape character which introduces RTF tags.
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
static byte[]firstIndent
First indent tag.
static byte[]fontArial
Font Arial tag.
static byte[]fontCharset
Font charset tag.
protected static byte[]fontColor
Font color tag.
static byte[]fontCourier
Font Courier tag.
ArrayListfontList
This ArrayList contains all fonts used in the document.
static byte[]fontModern
Modern font tag.
protected static bytefontNumber
Font number tag.
static byte[]fontRoman
Roman font tag.
protected static byte[]fontSize
Font size tag.
static byte[]fontSwiss
Swiss font tag.
static byte[]fontSymbol
Font Symbol tag.
static byte[]fontTable
Begin the font table tag.
static byte[]fontTech
Tech font tag.
static byte[]fontTimesNewRoman
Font Times New Roman tag.
static byte[]fontWindings
Font Windings tag.
HeaderFooterfooter
Document footer.
static byte[]footerBegin
Begin footer group tag.
static byte[]footerfBegin
static byte[]footerlBegin
static byte[]footerrBegin
booleanhasTitlePage
Special title page
HeaderFooterheader
Document header.
static byte[]headerBegin
Begin header group tag.
static byte[]headerfBegin
static byte[]headerlBegin
static byte[]headerrBegin
static byte[]hour
Hour tag.
static byte[]hybridList
RTF Writer outputs hybrid lists
ByteArrayOutputStreaminfo
This ByteArrayOutputStream contains the information group.
static byte[]infoBegin
Begin the info group tag.
booleaninHeaderFooter
Currently writing either Header or Footer
booleaninTable
Currently writing a Table
protected static byteitalic
Italic tag.
booleanlandscape
Landscape or Portrait Document
static byte[]landscapeTag1
Document Landscape tag 1.
static byte[]landscapeTag2
Document Landscape tag 2.
static byte[]listBegin
Actual list begin
static byte[]listBulletOld
Old Bullet Style
static byte[]listCurrentLevel
Current list level
static byte[]listDefinition
Begin a List definition
ArrayListlistIds
List of current Lists.
static byte[]listID
Current List ID
static byte[]listIndent
Left indent tag.
intlistLevel
Current List Level.
static byte[]listLevelAlignNew
Level alignment (new)
static byte[]listLevelAlignOld
Level alignment (old)
static byte[]listLevelDefinition
Current List level
static byte[]listLevelNumbers
Filler for Level Numbers
static byte[]listLevelNumbersDefinition
Level Numbers Definition
static byte[]listLevelStartAt
Level starting number
static byte[]listLevelTextDefinition
Level text group
static byte[]listLevelTextLength
Filler for Level Text Length
static byte[]listLevelTextStyleBullet
Level Text Bullet Style
static byte[]listLevelTextStyleNumbers
Level Text Numbering Style
static byte[]listLevelTypeNew
Level numbering (new)
static byte[]listLevelTypeOld
Level numbering (old)
ByteArrayOutputStreamlistoverride
This ByteArrayOutputStream contains the list override table.
static byte[]listoverridetableGroup
Begin the List Override Table
static byte[]listOverride
List override
static byte[]listOverrideCount
Number of overrides
ByteArrayOutputStreamlisttable
This ByteArrayOutputStream contains the list table.
static byte[]listtableGroup
Begin the List Table
static byte[]listTemplateID
List Template ID
static byte[]listTextOld
List text group for older browsers
intmarginBottom
Bottom margin.
intmarginLeft
Left margin.
intmarginRight
Right margin.
intmarginTop
Top margin.
intmaxListLevel
Current maximum List Level.
static byte[]metaAuthor
Author tag.
static byte[]metaCreationDate
Creation Date tag.
static byte[]metaKeywords
Keywords tag.
static byte[]metaProducer
Producer tag.
static byte[]metaSubject
Subject tag.
static byte[]metaTitle
Title tag.
static byte[]minute
Minute tag.
static byte[]month
Month tag.
static byte[]newPage
New Page tag.
static byteopenGroup
This is the character for beginning a new group.
intpageHeight
Page height.
intpageWidth
Page width.
static byte[]paragraph
Begin new paragraph tag.
static byte[]paragraphDefaults
Reset paragraph defaults tag.
static byte[]picture
Begin the picture tag
static byte[]pictureBMP
BMP Image
static byte[]pictureGroup
Begin the main Picture group tag
static byte[]pictureHeight
Picture height
static byte[]pictureJPEG
JPEG Image
static byte[]picturePNG
PNG Image
static byte[]pictureScaleX
Picture scale horizontal percent
static byte[]pictureScaleY
Picture scale vertical percent
static byte[]pictureWidth
Picture width
static byte[]pictureWMF
WMF Image
static byte[]rightIndent
Right indent tag.
static byte[]rtfMarginBottom
Margin bottom tag.
static byte[]rtfMarginLeft
Margin left tag.
static byte[]rtfMarginRight
Margin right tag.
static byte[]rtfMarginTop
Margin top tag.
static byte[]rtfPaperHeight
Paper height tag.
static byte[]rtfPaperWidth
Paper width tag.
static byte[]second
Second tag.
static byte[]section
Begin new section tag.
static byte[]sectionDefaults
Reset section defaults tag.
static byte[]sectionPageHeight
Page height of a section.
static byte[]sectionPageWidth
Page width of a section.
static byte[]startSub
Start subscript.
static byte[]startSuper
Start superscript.
protected static byte[]strikethrough
Strikethrough tag.
static byte[]tab
Tab
static byte[]tabStop
Tab Stop
static byte[]titlePage
Title Page tag
static doubleTWIPSFACTOR
Factor to use when converting.
protected static byte[]underline
Underline tag.
booleanwriteTOC
Write a TOC
static byte[]year
Year tag.
Constructor Summary
protected RtfWriter(Document doc, OutputStream os)
Constructs a RtfWriter.
Method Summary
booleanadd(Element element)
Signals that an Element was added to the Document.
protected intaddColor(Color newColor)
Add a new Color to the list of colours.
protected booleanaddElement(Element element, ByteArrayOutputStream out)
Adds an Element to the Document.
protected intaddFont(Font newFont)
Add a new Font to the list of fonts.
voidaddHeaderFooterFontColor(HeaderFooter hf)
voidclose()
Signals that the Document was closed and that no other Elements will be added.
static StringfilterSpecialChar(String str, boolean useHex)
Replaces special characters with their unicode values
booleangetGeneratingTOCEntries()
Gets the current setting of writeTOC
booleangetHasTitlePage()
Gets the current setting of hasTitlePage
static RtfWritergetInstance(Document document, OutputStream os)
Gets an instance of the RtfWriter.
booleangetLandscape()
Returns the current landscape setting
intgetRandomInt()
Get a random integer.
voidinitDefaults()
Initialise all helper classes.
booleannewPage()
Tells the RtfWriter that a new page is to be begun.
voidopen()
Signals that the Document has been opened and that Elements can be added.
booleanparseFormat(Rectangle pageSize, boolean rotate)
This method tries to fit the Rectangle pageSize to one of the predefined PageSize rectangles.
voidprocessHeaderFooter(HeaderFooter hf)
booleanrectEquals(Rectangle rect1, Rectangle rect2)
This method compares to Rectangles.
voidresetFooter()
Resets the footer.
voidresetHeader()
Resets the header.
voidsetFooter(HeaderFooter footer)
Adds the footer to the bottom of the Document.
voidsetGenerateTOCEntries(boolean writeTOC)
This method controls whether TOC entries are automatically generated
voidsetHasTitlePage(boolean hasTitlePage)
This method controls whether the first page is a title page
voidsetHeader(HeaderFooter header)
Adds the header to the top of the Document.
voidsetLandscape(boolean landscape)
Explicitly sets the page format to use.
booleansetMarginMirroring(boolean MarginMirroring)
booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the page margins
booleansetPageSize(Rectangle pageSize)
Sets the page size
voidwriteAnchor(Anchor anchor, ByteArrayOutputStream out)
Write an Anchor.
voidwriteAnnotation(Annotation annotationElement, ByteArrayOutputStream out)
Write an Annotation
voidwriteChunk(Chunk chunk, ByteArrayOutputStream out)
Write a Chunk and all its font properties.
voidwriteColorList()
Write the colour list to the final ByteArrayOutputStream
booleanwriteDocument()
Merge all the different ArrayLists and ByteArrayOutputStreams to the final ByteArrayOutputStream
voidwriteDocumentFormat()
Write the Document's Paper and Margin Size to the final ByteArrayOutputStream
voidwriteDocumentIntro()
Write the Rich Text file settings
protected voidwriteFinishingFontSignature(OutputStream out, Chunk chunk)
voidwriteFontList()
Write the font list to the final ByteArrayOutputStream
voidwriteFormatedDateTime(String date)
Writes a date.
voidwriteHeaderFooter(HeaderFooter headerFooter, byte[] hfType, ByteArrayOutputStream target)
Write a HeaderFooter to a ByteArrayOutputStream
voidwriteHeadersFooters(ByteArrayOutputStream os)
Write the current header and footer to a ByteArrayOutputStream
voidwriteImage(Image image, ByteArrayOutputStream out)
Write an Image.
voidwriteInfoGroup()
Write the Information Group to the final ByteArrayOutputStream
protected voidwriteInitialFontSignature(OutputStream out, Chunk chunk)
static voidwriteInt(OutputStream out, int i)
Write an integer
voidwriteList(List list, ByteArrayOutputStream out)
Write a List
voidwriteList()
Write the listtable and listoverridetable to the final ByteArrayOutputStream
voidwriteListElement(ListItem listItem, ByteArrayOutputStream out)
Write a ListItem
voidwriteMeta(byte[] metaName, Meta meta)
Add a Meta element.
voidwriteParagraph(Paragraph paragraphElement, ByteArrayOutputStream out)
Write the beginning of a new Paragraph
voidwritePhrase(Phrase phrase, ByteArrayOutputStream out)
Write a Phrase.
voidwriteSection(Section sectionElement, ByteArrayOutputStream out)
Write the beginning of a new Section
voidwriteSectionDefaults(ByteArrayOutputStream out)
Writes the default values for the current Section
voidwriteTable(Table table, ByteArrayOutputStream out)
Write a Table.
booleanwriteTOC(String tocTitle, Font titleFont, boolean showTOCasEntry, Font showTOCEntryFont)
Write the table of contents.
booleanwritingHeaderFooter()
Returns whether we are currently writing a header or footer

Field Detail

alignCenter

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

alignJustify

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

alignLeft

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

alignRight

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

annotation

private static final byte[] annotation
Annotation text tag.

annotationAuthor

private static final byte[] annotationAuthor
Annotation Author tag.

annotationID

private static final byte[] annotationID
Annotation ID tag.

ansi

private static final byte[] ansi
RTF encoding.

ansiCodepage

private static final byte[] ansiCodepage
RTF encoding codepage.

bold

protected static final byte bold
Bold tag.

closeGroup

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

colorBlue

private static final byte[] colorBlue
Blue value tag.

colorGreen

private static final byte[] colorGreen
Green value tag.

colorList

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

colorRed

private static final byte[] colorRed
Red value tag.

colorTable

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

commaDelimiter

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

content

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

currentListID

private int currentListID
Current list ID.

day

private static final byte[] day
Day tag.

defaultFont

private static final byte[] defaultFont
Default Font.

delimiter

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

docBegin

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

endSuperSub

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

escape

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

extendedEscape

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

facingPages

private static final byte[] facingPages
Facing pages tag

field

protected static final byte[] field
Begin field tag

fieldContent

protected static final byte[] fieldContent
Content fo the field

fieldDisplay

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

fieldHyperlink

protected static final byte[] fieldHyperlink
HYPERLINK field

fieldPage

protected static final byte[] fieldPage
PAGE numbers

firstIndent

private static final byte[] firstIndent
First indent tag.

fontArial

private static final byte[] fontArial
Font Arial tag.

fontCharset

private static final byte[] fontCharset
Font charset tag.

fontColor

protected static final byte[] fontColor
Font color tag.

fontCourier

private static final byte[] fontCourier
Font Courier tag.

fontList

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

fontModern

private static final byte[] fontModern
Modern font tag.

fontNumber

protected static final byte fontNumber
Font number tag.

fontRoman

private static final byte[] fontRoman
Roman font tag.

fontSize

protected static final byte[] fontSize
Font size tag.

fontSwiss

private static final byte[] fontSwiss
Swiss font tag.

fontSymbol

private static final byte[] fontSymbol
Font Symbol tag.

fontTable

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

fontTech

private static final byte[] fontTech
Tech font tag.

fontTimesNewRoman

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

fontWindings

private static final byte[] fontWindings
Font Windings tag.

footer

private HeaderFooter footer
Document footer.

footerBegin

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

footerfBegin

private static final byte[] footerfBegin

footerlBegin

private static final byte[] footerlBegin

footerrBegin

private static final byte[] footerrBegin

hasTitlePage

private boolean hasTitlePage
Special title page

header

private HeaderFooter header
Document header.

headerBegin

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

headerfBegin

private static final byte[] headerfBegin

headerlBegin

private static final byte[] headerlBegin

headerrBegin

private static final byte[] headerrBegin

hour

private static final byte[] hour
Hour tag.

hybridList

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

info

private ByteArrayOutputStream info
This ByteArrayOutputStream contains the information group.

infoBegin

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

inHeaderFooter

private boolean inHeaderFooter
Currently writing either Header or Footer

inTable

private boolean inTable
Currently writing a Table

italic

protected static final byte italic
Italic tag.

landscape

private boolean landscape
Landscape or Portrait Document

landscapeTag1

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

landscapeTag2

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

listBegin

private static final byte[] listBegin
Actual list begin

listBulletOld

private static final byte[] listBulletOld
Old Bullet Style

listCurrentLevel

private static final byte[] listCurrentLevel
Current list level

listDefinition

private static final byte[] listDefinition
Begin a List definition

listIds

private ArrayList listIds
List of current Lists.

listID

private static final byte[] listID
Current List ID

listIndent

private static final byte[] listIndent
Left indent tag.

listLevel

private int listLevel
Current List Level.

listLevelAlignNew

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

listLevelAlignOld

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

listLevelDefinition

private static final byte[] listLevelDefinition
Current List level

listLevelNumbers

private static final byte[] listLevelNumbers
Filler for Level Numbers

listLevelNumbersDefinition

private static final byte[] listLevelNumbersDefinition
Level Numbers Definition

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

listLevelTextStyleBullet

private static final byte[] listLevelTextStyleBullet
Level Text Bullet Style

listLevelTextStyleNumbers

private static final byte[] listLevelTextStyleNumbers
Level Text Numbering Style

listLevelTypeNew

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

listLevelTypeOld

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

listoverride

private ByteArrayOutputStream listoverride
This ByteArrayOutputStream contains the list override table.

listoverridetableGroup

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

listOverride

private static final byte[] listOverride
List override

listOverrideCount

private static final byte[] listOverrideCount
Number of overrides

listtable

private ByteArrayOutputStream listtable
This ByteArrayOutputStream contains the list table.

listtableGroup

private static final byte[] listtableGroup
Begin the List Table

listTemplateID

private static final byte[] listTemplateID
List Template ID

listTextOld

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

marginBottom

private int marginBottom
Bottom margin.

marginLeft

private int marginLeft
Left margin.

marginRight

private int marginRight
Right margin.

marginTop

private int marginTop
Top margin.

maxListLevel

private int maxListLevel
Current maximum List Level.

metaAuthor

private static final byte[] metaAuthor
Author tag.

metaCreationDate

private static final byte[] metaCreationDate
Creation Date tag.

metaKeywords

private static final byte[] metaKeywords
Keywords tag.

metaProducer

private static final byte[] metaProducer
Producer tag.

metaSubject

private static final byte[] metaSubject
Subject tag.

metaTitle

private static final byte[] metaTitle
Title tag.

minute

private static final byte[] minute
Minute tag.

month

private static final byte[] month
Month tag.

newPage

private static final byte[] newPage
New Page tag.

openGroup

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

pageHeight

private int pageHeight
Page height.

pageWidth

private int pageWidth
Page width.

paragraph

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

paragraphDefaults

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

picture

private static final byte[] picture
Begin the picture tag

pictureBMP

private static final byte[] pictureBMP
BMP Image

pictureGroup

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

pictureHeight

private static final byte[] pictureHeight
Picture height

pictureJPEG

private static final byte[] pictureJPEG
JPEG Image

picturePNG

private static final byte[] picturePNG
PNG Image

pictureScaleX

private static final byte[] pictureScaleX
Picture scale horizontal percent

pictureScaleY

private static final byte[] pictureScaleY
Picture scale vertical percent

pictureWidth

private static final byte[] pictureWidth
Picture width

pictureWMF

private static final byte[] pictureWMF
WMF Image

rightIndent

private static final byte[] rightIndent
Right indent tag.

rtfMarginBottom

private static final byte[] rtfMarginBottom
Margin bottom 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.

rtfPaperHeight

private static final byte[] rtfPaperHeight
Paper height tag.

rtfPaperWidth

private static final byte[] rtfPaperWidth
Paper width tag.

second

private static final byte[] second
Second tag.

section

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

sectionDefaults

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

sectionPageHeight

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

sectionPageWidth

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

startSub

private static final byte[] startSub
Start subscript.

startSuper

private static final byte[] startSuper
Start superscript.

strikethrough

protected static final byte[] strikethrough
Strikethrough tag.

tab

private static final byte[] tab
Tab

tabStop

private static final byte[] tabStop
Tab Stop

titlePage

private static final byte[] titlePage
Title Page tag

TWIPSFACTOR

public static final double TWIPSFACTOR
Factor to use when converting.

underline

protected static final byte[] underline
Underline tag.

writeTOC

private boolean writeTOC
Write a TOC

year

private static final byte[] year
Year tag.

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

add

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

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

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

addElement

protected boolean addElement(Element element, ByteArrayOutputStream out)
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

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

addHeaderFooterFontColor

private void addHeaderFooterFontColor(HeaderFooter hf)

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

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

getGeneratingTOCEntries

public boolean getGeneratingTOCEntries()
Gets the current setting of writeTOC

Returns: boolean value indicating whether a TOC is being generated

getHasTitlePage

public boolean getHasTitlePage()
Gets the current setting of hasTitlePage

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

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

getLandscape

public boolean getLandscape()
Returns the current landscape setting

Returns: boolean value indicating the current page format

getRandomInt

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

Returns: Random int value.

initDefaults

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

newPage

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

Returns: true if a new Page was begun.

Throws: DocumentException if the Document was not open or had been closed.

open

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

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

processHeaderFooter

private void processHeaderFooter(HeaderFooter hf)

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

resetFooter

public void resetFooter()
Resets the footer.

resetHeader

public void resetHeader()
Resets the header.

setFooter

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

Parameters: footer

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

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

setHeader

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

Parameters: header

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

setMarginMirroring

public boolean setMarginMirroring(boolean MarginMirroring)

See Also: DocListener

setMargins

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

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

Parameters: pageSize A Rectangle specifying the page size

Returns: true if the page size was set

writeAnchor

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

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

Throws: IOException

writeAnnotation

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

Parameters: annotationElement The Annotation to be written out The ByteArrayOutputStream to write to

Throws: IOException

writeChunk

private void writeChunk(Chunk chunk, ByteArrayOutputStream out)
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

writeColorList

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

Throws: IOException

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

writeDocumentFormat

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

Throws: IOException

writeDocumentIntro

private void writeDocumentIntro()
Write the Rich Text file settings

Throws: IOException

writeFinishingFontSignature

protected void writeFinishingFontSignature(OutputStream out, Chunk chunk)

writeFontList

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

Throws: IOException

writeFormatedDateTime

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

Parameters: date The date to be written

Throws: IOException

writeHeaderFooter

private void writeHeaderFooter(HeaderFooter headerFooter, byte[] hfType, ByteArrayOutputStream target)
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

writeHeadersFooters

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

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

Throws: IOException

writeImage

private void writeImage(Image image, ByteArrayOutputStream out)
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

writeInfoGroup

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

Throws: IOException

writeInitialFontSignature

protected void writeInitialFontSignature(OutputStream out, Chunk chunk)

writeInt

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

writeList

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

Parameters: list The List to be written out The ByteArrayOutputStream to write to

Throws: IOException DocumentException

writeList

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

Throws: IOException

writeListElement

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

Parameters: listItem The ListItem to be written out The ByteArrayOutputStream to write to

Throws: IOException DocumentException

writeMeta

private void writeMeta(byte[] metaName, Meta meta)
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

writeParagraph

private void writeParagraph(Paragraph paragraphElement, ByteArrayOutputStream out)
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)
Write a Phrase.

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

Throws: IOException

writeSection

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

Parameters: sectionElement The Section be written out The ByteArrayOutputStream to write to

Throws: IOException DocumentException

writeSectionDefaults

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

Parameters: out The ByteArrayOutputStream to be written to

Throws: IOException

writeTable

private void writeTable(Table table, ByteArrayOutputStream out)
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

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.

writingHeaderFooter

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

Returns: the value of inHeaderFooter