Save This Page
Home » iText-src-2.1.3 » com.lowagie » text » rtf » [javadoc | source]
com.lowagie.text.rtf
public class: RtfWriter [javadoc | source]
java.lang.Object
   com.lowagie.text.DocWriter
      com.lowagie.text.rtf.RtfWriter

All Implemented Interfaces:
    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:

  • 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: < - a href="mailto:mhall@myrealbox.com">Mark.Hall@myrealbox.com
    author: Steffen - Stundzig
    author: < - a href="ericmattes@yahoo.com">Eric Mattes
    author: < - a href="raul.wegmann@uam.es">Raul Wegmann
Field Summary
public static final  byte escape    This is the escape character which introduces RTF tags. 
protected static final  byte delimiter    This is the delimiter between RTF tags and normal text. 
public static final  byte openGroup    This is the character for beginning a new group. 
public static final  byte closeGroup    This is the character for closing a group. 
protected static final  byte fontNumber    Font number tag. 
protected static final  byte[] fontSize    Font size tag. 
protected static final  byte[] fontColor    Font color tag. 
public static final  byte[] paragraphDefaults    Reset paragraph defaults tag. 
public static final  byte[] paragraph    Begin new paragraph tag. 
public static final  byte[] sectionPageWidth    Page width of a section. 
public static final  byte[] sectionPageHeight    Page height of a section. 
protected static final  byte bold    Bold tag. 
protected static final  byte italic    Italic tag. 
protected static final  byte[] underline    Underline tag. 
protected static final  byte[] strikethrough    Strikethrough tag. 
public static final  byte[] alignLeft    Text alignment left tag. 
public static final  byte[] alignCenter    Text alignment center tag. 
public static final  byte[] alignRight    Text alignment right tag. 
public static final  byte[] alignJustify    Text alignment justify tag. 
protected static final  byte[] field    Begin field tag 
protected static final  byte[] fieldContent    Content fo the field 
protected static final  byte[] fieldPage    PAGE numbers 
protected static final  byte[] fieldHyperlink    HYPERLINK field 
protected static final  byte[] fieldDisplay    Last page number (not used) 
public static final  double TWIPSFACTOR    Factor to use when converting. 
Fields inherited from com.lowagie.text.DocWriter:
NEWLINE,  TAB,  LT,  SPACE,  EQUALS,  QUOTE,  GT,  FORWARD,  pageSize,  document,  os,  open,  pause,  closeStream
Constructor:
 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 from com.lowagie.text.rtf.RtfWriter Summary:
add,   addColor,   addElement,   addFont,   close,   filterSpecialChar,   getGeneratingTOCEntries,   getHasTitlePage,   getInstance,   getLandscape,   newPage,   open,   resetFooter,   resetHeader,   setFooter,   setGenerateTOCEntries,   setHasTitlePage,   setHeader,   setLandscape,   setMarginMirroring,   setMargins,   setPageSize,   writeFinishingFontSignature,   writeHeadersFooters,   writeInitialFontSignature,   writeInt,   writeTOC,   writingHeaderFooter
Methods from com.lowagie.text.DocWriter:
add,   addTabs,   close,   flush,   getISOBytes,   isCloseStream,   isPaused,   newPage,   open,   pause,   resetFooter,   resetHeader,   resetPageCount,   resume,   setCloseStream,   setFooter,   setHeader,   setMarginMirroring,   setMargins,   setPageCount,   setPageSize,   write,   write,   writeEnd,   writeEnd,   writeMarkupAttributes,   writeStart
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.lowagie.text.rtf.RtfWriter Detail:
 public boolean add(Element element) throws DocumentException 
    Signals that an Element was added to the Document.
 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.
 protected boolean addElement(Element element,
    ByteArrayOutputStream out) throws DocumentException 
    Adds an Element to the Document.
 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.
 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

 public static final String filterSpecialChar(String str,
    boolean useHex) 
    Replaces special characters with their unicode values
 public boolean getGeneratingTOCEntries() 
    Gets the current setting of writeTOC
 public boolean getHasTitlePage() 
    Gets the current setting of hasTitlePage
 public static RtfWriter getInstance(Document document,
    OutputStream os) 
    Gets an instance of the RtfWriter.
 public boolean getLandscape() 
    Returns the current landscape setting
 public boolean newPage() throws DocumentException 
    Tells the RtfWriter that a new page is to be begun.
 public  void open() 
    Signals that the Document has been opened and that Elements can be added.
 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) 
    This method controls whether TOC entries are automatically generated
 public  void setHasTitlePage(boolean hasTitlePage) 
    This method controls whether the first page is a title page
 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. Otherwise the RtfWriter will try to guess the format by comparing pagewidth and pageheight
 public boolean setMarginMirroring(boolean MarginMirroring) 
 public boolean setMargins(float marginLeft,
    float marginRight,
    float marginTop,
    float marginBottom) 
    Sets the page margins
 public boolean setPageSize(Rectangle pageSize) 
    Sets the page size
 protected  void writeFinishingFontSignature(OutputStream out,
    Chunk chunk) throws IOException 
 public  void writeHeadersFooters(ByteArrayOutputStream os) throws IOException 
    Write the current header and footer to a ByteArrayOutputStream
 protected  void writeInitialFontSignature(OutputStream out,
    Chunk chunk) throws IOException 
 public static final  void writeInt(OutputStream out,
    int i) throws IOException 
    Write an integer
 public boolean writeTOC(String tocTitle,
    Font titleFont,
    boolean showTOCasEntry,
    Font showTOCEntryFont) 
    Write the table of contents.
 public boolean writingHeaderFooter() 
    Returns whether we are currently writing a header or footer