| java.lang.Object com.lowagie.text.DocWriter com.lowagie.text.rtf.RtfWriter
RtfWriter | public class RtfWriter extends DocWriter (Code) | | 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:
- Watermarks
- Viewer preferences
- Encryption
- Embedded fonts
- Phrases with a leading
- Lists with non-bullet symbols
- Nested tables
- Images other than JPEG and PNG
- Rotated images
author: Mark Hall (mhall@edu.uni-klu.ac.at) author: Steffen Stundzig (Steffen.Stundzig@smb-tec.com) author: Eric Mattes (ericmattes@yahoo.com) author: Raul Wegmann (raul.wegmann@uam.es) |
Field Summary | |
final public static double | TWIPSFACTOR Factor to use when converting. | final public static byte[] | alignCenter Text alignment center tag. | final public static byte[] | alignJustify Text alignment justify tag. | final public static byte[] | alignLeft Text alignment left tag. | final public static byte[] | alignRight Text alignment right tag. | final protected static byte | bold Bold tag. | final public static byte | closeGroup This is the character for closing a group. | final protected static byte | delimiter This is the delimiter between RTF tags and normal text. | final public static byte | escape This is the escape character which introduces RTF tags. | final protected static byte[] | field | final protected static byte[] | fieldContent | final protected static byte[] | fieldDisplay | final protected static byte[] | fieldHyperlink | final protected static byte[] | fieldPage | final protected static byte[] | fontColor Font color tag. | final protected static byte | fontNumber Font number tag. | final protected static byte[] | fontSize Font size tag. | final protected static byte | italic Italic tag. | final public static byte | openGroup This is the character for beginning a new group. | final public static byte[] | paragraph Begin new paragraph tag. | final public static byte[] | paragraphDefaults Reset paragraph defaults tag. | final public static byte[] | sectionPageHeight Page height of a section. | final public static byte[] | sectionPageWidth Page width of a section. | final protected static byte[] | strikethrough Strikethrough tag. | final protected static byte[] | underline Underline tag. |
Method Summary | |
public 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. | public void | close() Signals that the Document was closed and that no other
Elements will be added. | final public static String | filterSpecialChar(String str, boolean useHex) | public boolean | getGeneratingTOCEntries() | public boolean | getHasTitlePage() | public static RtfWriter | getInstance(Document document, OutputStream os) Gets an instance of the RtfWriter .
Parameters: document - The Document that has to be written Parameters: os - The OutputStream the writer has to write to. | public boolean | getLandscape() | public boolean | newPage() Tells the RtfWriter that a new page is to be begun. | public void | resetFooter() Resets the footer. | public void | resetHeader() Resets the header. | public void | setFooter(HeaderFooter footer) Adds the footer to the bottom of the Document . | public void | setGenerateTOCEntries(boolean writeTOC) | public void | setHasTitlePage(boolean hasTitlePage) | public void | setHeader(HeaderFooter header) Adds the header to the top of the Document . | public void | setLandscape(boolean landscape) Explicitly sets the page format to use. | public boolean | setMarginMirroring(boolean MarginMirroring) | public boolean | setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) | public boolean | setPageSize(Rectangle pageSize) | protected void | writeFinishingFontSignature(OutputStream out, Chunk chunk) | public void | writeHeadersFooters(ByteArrayOutputStream os) | protected void | writeInitialFontSignature(OutputStream out, Chunk chunk) | final public static void | writeInt(OutputStream out, int i) | public boolean | writeTOC(String tocTitle, Font titleFont, boolean showTOCasEntry, Font showTOCEntryFont) Write the table of contents. | public boolean | writingHeaderFooter() |
TWIPSFACTOR | final public static double TWIPSFACTOR(Code) | | Factor to use when converting.
|
alignCenter | final public static byte[] alignCenter(Code) | | Text alignment center tag.
|
alignJustify | final public static byte[] alignJustify(Code) | | Text alignment justify tag.
|
alignLeft | final public static byte[] alignLeft(Code) | | Text alignment left tag.
|
alignRight | final public static byte[] alignRight(Code) | | Text alignment right tag.
|
bold | final protected static byte bold(Code) | | Bold tag.
|
closeGroup | final public static byte closeGroup(Code) | | This is the character for closing a group.
|
delimiter | final protected static byte delimiter(Code) | | This is the delimiter between RTF tags and normal text.
|
escape | final public static byte escape(Code) | | This is the escape character which introduces RTF tags.
|
field | final protected static byte[] field(Code) | | Begin field tag
|
fieldContent | final protected static byte[] fieldContent(Code) | | Content fo the field
|
fieldDisplay | final protected static byte[] fieldDisplay(Code) | | Last page number (not used)
|
fieldHyperlink | final protected static byte[] fieldHyperlink(Code) | | HYPERLINK field
|
fieldPage | final protected static byte[] fieldPage(Code) | | PAGE numbers
|
fontColor | final protected static byte[] fontColor(Code) | | Font color tag.
|
fontNumber | final protected static byte fontNumber(Code) | | Font number tag.
|
fontSize | final protected static byte[] fontSize(Code) | | Font size tag.
|
italic | final protected static byte italic(Code) | | Italic tag.
|
openGroup | final public static byte openGroup(Code) | | This is the character for beginning a new group.
|
paragraph | final public static byte[] paragraph(Code) | | Begin new paragraph tag.
|
paragraphDefaults | final public static byte[] paragraphDefaults(Code) | | Reset paragraph defaults tag.
|
sectionPageHeight | final public static byte[] sectionPageHeight(Code) | | Page height of a section.
|
sectionPageWidth | final public static byte[] sectionPageWidth(Code) | | Page width of a section.
|
strikethrough | final protected static byte[] strikethrough(Code) | | Strikethrough tag.
|
underline | final protected static byte[] underline(Code) | | Underline tag.
|
RtfWriter | protected RtfWriter(Document doc, OutputStream os)(Code) | | Constructs a RtfWriter .
Parameters: doc - The Document that is to be written as RTF Parameters: os - The OutputStream the writer has to write to. |
add | public boolean add(Element element) throws DocumentException(Code) | | Signals that an Element was added to the Document .
Parameters: element - A high level object to add 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)(Code) | | 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 The index of the color in the colour list |
addElement | protected boolean addElement(Element element, ByteArrayOutputStream out) throws DocumentException(Code) | | Adds an Element to the Document .
Parameters: element - the high level element to add Parameters: out - the outputstream to which the RTF data is sent 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)(Code) | | 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 The index of the Font in the font list |
close | public void close()(Code) | | 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 | final public static String filterSpecialChar(String str, boolean useHex)(Code) | | Replaces special characters with their unicode values
Parameters: str - The original String Parameters: useHex - The converted String |
getGeneratingTOCEntries | public boolean getGeneratingTOCEntries()(Code) | | Gets the current setting of writeTOC
boolean value indicating whether a TOC is being generated |
getHasTitlePage | public boolean getHasTitlePage()(Code) | | Gets the current setting of hasTitlePage
boolean value indicating whether the first page is a title page |
getInstance | public static RtfWriter getInstance(Document document, OutputStream os)(Code) | | Gets an instance of the RtfWriter .
Parameters: document - The Document that has to be written Parameters: os - The OutputStream the writer has to write to. a new RtfWriter |
getLandscape | public boolean getLandscape()(Code) | | Returns the current landscape setting
boolean value indicating the current page format |
newPage | public boolean newPage()(Code) | | Tells the RtfWriter that a new page is to be begun.
true if a new Page was begun. throws: DocumentException - if the Document was not open or had been closed. |
resetFooter | public void resetFooter()(Code) | | Resets the footer.
|
resetHeader | public void resetHeader()(Code) | | Resets the header.
|
setFooter | public void setFooter(HeaderFooter footer)(Code) | | Adds the footer to the bottom of the Document .
Parameters: footer - |
setGenerateTOCEntries | public void setGenerateTOCEntries(boolean writeTOC)(Code) | | 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)(Code) | | 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)(Code) | | Adds the header to the top of the Document .
Parameters: header - |
setLandscape | public void setLandscape(boolean landscape)(Code) | | 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 |
setMargins | public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)(Code) | | Sets the page margins
Parameters: marginLeft - The left margin Parameters: marginRight - The right margin Parameters: marginTop - The top margin Parameters: marginBottom - The bottom margin true if the page margins were set. |
setPageSize | public boolean setPageSize(Rectangle pageSize)(Code) | | Sets the page size
Parameters: pageSize - A Rectangle specifying the page size true if the page size was set |
writeHeadersFooters | public void writeHeadersFooters(ByteArrayOutputStream os) throws IOException(Code) | | Write the current header and footer to a ByteArrayOutputStream
Parameters: os - The ByteArrayOutputStream to which the header and footer will be written. throws: IOException - |
writeInt | final public static void writeInt(OutputStream out, int i) throws IOException(Code) | | Write an integer
Parameters: out - The OuputStream to which the int value is to be written Parameters: i - The int value to be written throws: IOException - |
writeTOC | public boolean writeTOC(String tocTitle, Font titleFont, boolean showTOCasEntry, Font showTOCEntryFont)(Code) | | Write the table of contents.
Parameters: tocTitle - The title that will be displayed above the TOC Parameters: titleFont - The Font that will be used for the tocTitle Parameters: showTOCasEntry - Set this to true if you want the TOC to appear as an entry in the TOC Parameters: showTOCEntryFont - Use this Font to specify what Font to use when showTOCasEntry is true true if the TOC was added. |
writingHeaderFooter | public boolean writingHeaderFooter()(Code) | | Returns whether we are currently writing a header or footer
the value of inHeaderFooter |
|
|