com.lowagie.text.rtf
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. ADocWriter
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:
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 byte | bold Bold tag. |
static byte | closeGroup This is the character for closing a group. |
static byte[] | colorBlue Blue value tag. |
static byte[] | colorGreen Green value tag. |
ArrayList | colorList This ArrayList contains all colours used in the document. |
static byte[] | colorRed Red value tag. |
static byte[] | colorTable Begin colour table tag. |
static byte | commaDelimiter This is another delimiter between RTF tags and normal text. |
ByteArrayOutputStream | content This ByteArrayOutputStream contains the main body of the document. |
int | currentListID Current list ID. |
static byte[] | day Day tag. |
static byte[] | defaultFont Default Font. |
protected static byte | delimiter 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 byte | escape 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. |
ArrayList | fontList This ArrayList contains all fonts used in the document. |
static byte[] | fontModern Modern font tag. |
protected static byte | fontNumber 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. |
HeaderFooter | footer Document footer. |
static byte[] | footerBegin Begin footer group tag. |
static byte[] | footerfBegin |
static byte[] | footerlBegin |
static byte[] | footerrBegin |
boolean | hasTitlePage Special title page |
HeaderFooter | header 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 |
ByteArrayOutputStream | info This ByteArrayOutputStream contains the information group. |
static byte[] | infoBegin Begin the info group tag. |
boolean | inHeaderFooter Currently writing either Header or Footer |
boolean | inTable Currently writing a Table |
protected static byte | italic Italic tag. |
boolean | landscape 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 |
ArrayList | listIds List of current Lists. |
static byte[] | listID Current List ID |
static byte[] | listIndent Left indent tag. |
int | listLevel 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) |
ByteArrayOutputStream | listoverride 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 |
ByteArrayOutputStream | listtable 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 |
int | marginBottom Bottom margin. |
int | marginLeft Left margin. |
int | marginRight Right margin. |
int | marginTop Top margin. |
int | maxListLevel 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 byte | openGroup This is the character for beginning a new group. |
int | pageHeight Page height. |
int | pageWidth 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 double | TWIPSFACTOR Factor to use when converting. |
protected static byte[] | underline Underline tag. |
boolean | writeTOC Write a TOC |
static byte[] | year Year tag. |
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. |
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
|
int | getRandomInt()
Get a random integer.
|
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. |
boolean | parseFormat(Rectangle pageSize, boolean rotate)
This method tries to fit the Rectangle pageSize to one of the predefined PageSize rectangles.
|
void | processHeaderFooter(HeaderFooter hf) |
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) |
boolean | setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the page margins
|
boolean | setPageSize(Rectangle pageSize)
Sets the page size
|
void | writeAnchor(Anchor anchor, ByteArrayOutputStream out)
Write an Anchor . |
void | writeAnnotation(Annotation annotationElement, ByteArrayOutputStream out)
Write an Annotation
|
void | writeChunk(Chunk chunk, ByteArrayOutputStream out)
Write a Chunk and all its font properties.
|
void | writeColorList()
Write the colour list to the final ByteArrayOutputStream |
boolean | writeDocument()
Merge all the different ArrayList s and ByteArrayOutputStream s
to the final ByteArrayOutputStream
|
void | writeDocumentFormat()
Write the Document 's Paper and Margin Size
to the final ByteArrayOutputStream |
void | writeDocumentIntro() Write the Rich Text file settings |
protected void | writeFinishingFontSignature(OutputStream out, Chunk chunk) |
void | writeFontList()
Write the font list to the final ByteArrayOutputStream |
void | writeFormatedDateTime(String date)
Writes a date. |
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
|
void | writeImage(Image image, ByteArrayOutputStream out)
Write an Image .
|
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
|
void | writeList(List list, ByteArrayOutputStream out)
Write a List
|
void | writeList()
Write the listtable and listoverridetable to the final ByteArrayOutputStream |
void | writeListElement(ListItem listItem, ByteArrayOutputStream out)
Write a ListItem
|
void | writeMeta(byte[] metaName, Meta meta)
Add a Meta element. |
void | writeParagraph(Paragraph paragraphElement, ByteArrayOutputStream out)
Write the beginning of a new Paragraph
|
void | writePhrase(Phrase phrase, ByteArrayOutputStream out)
Write a Phrase .
|
void | writeSection(Section sectionElement, ByteArrayOutputStream out)
Write the beginning of a new Section
|
void | writeSectionDefaults(ByteArrayOutputStream out)
Writes the default values for the current Section
|
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
|
ArrayList
contains all colours used in the document.ByteArrayOutputStream
contains the main body of the document.ArrayList
contains all fonts used in the document.ByteArrayOutputStream
contains the information group.ByteArrayOutputStream
contains the list override table.ByteArrayOutputStream
contains the list table.RtfWriter
.
Parameters: doc The Document
that is to be written as RTF os The OutputStream
the writer has to write to.
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
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
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
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
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
Parameters: str The original String
useHex
Returns: The converted String
Returns: boolean value indicating whether a TOC is being generated
Returns: boolean value indicating whether the first page is a title page
RtfWriter
.
Parameters: document The Document
that has to be written os The OutputStream
the writer has to write to.
Returns: a new RtfWriter
Returns: boolean value indicating the current page format
Returns: Random int
value.
ByteArrayOutputStream
'sRtfWriter
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.
Document
has been opened and that
Elements
can be added.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
Parameters: rect1 rect2
Returns: true if rect1 and rect2 represent the same rectangle
Document
.Parameters: footer
Parameters: writeTOC boolean value indicating whether a TOC is to be generated
Parameters: hasTitlePage boolean value indicating whether the first page is a title page
Document
.Parameters: header
Parameters: landscape boolean value indicating whether we are using landscape format or not
See Also: DocListener
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.
Parameters: pageSize A Rectangle
specifying the page size
Returns: true
if the page size was set
Anchor
. Anchors are treated like Phrases.
Parameters: anchor The Chunk
item to be written out The ByteArrayOutputStream
to write to
Throws: IOException
Annotation
Parameters: annotationElement The Annotation
to be written out The ByteArrayOutputStream
to write to
Throws: IOException
Chunk
and all its font properties.
Parameters: chunk The Chunk
item to be written out The ByteArrayOutputStream
to write to
Throws: IOException DocumentException
ByteArrayOutputStream
Throws: IOException
ArrayList
s and ByteArrayOutputStream
s
to the final ByteArrayOutputStream
Returns: true
if all information was sucessfully written to the ByteArrayOutputStream
Document
's Paper and Margin Size
to the final ByteArrayOutputStream
Throws: IOException
Throws: IOException
ByteArrayOutputStream
Throws: IOException
Parameters: date The date to be written
Throws: IOException
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
ByteArrayOutputStream
Parameters: os The ByteArrayOutputStream
to which the header and footer will be written.
Throws: IOException
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
ByteArrayOutputStream
Throws: IOException
Parameters: out The OuputStream
to which the int
value is to be written i The int
value to be written
Throws: IOException
List
Parameters: list The List
to be written out The ByteArrayOutputStream
to write to
Throws: IOException DocumentException
ByteArrayOutputStream
Throws: IOException
ListItem
Parameters: listItem The ListItem
to be written out The ByteArrayOutputStream
to write to
Throws: IOException DocumentException
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
Paragraph
Parameters: paragraphElement The Paragraph
to be written out The ByteArrayOutputStream
to write to
Throws: IOException
Phrase
.
Parameters: phrase The Phrase
item to be written out The ByteArrayOutputStream
to write to
Throws: IOException
Section
Parameters: sectionElement The Section
be written out The ByteArrayOutputStream
to write to
Throws: IOException DocumentException
Parameters: out The ByteArrayOutputStream
to be written to
Throws: IOException
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
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.
Returns: the value of inHeaderFooter