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

All Implemented Interfaces:
    DocListener

A DocWriter class for HTML.

An HtmlWriter 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 HtmlWriter.

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 HTML to the Standard OutputStream
HtmlWriter.getInstance(document, System.out);
// this will write HTML to a file called text.html
HtmlWriter.getInstance(document, new FileOutputStream("text.html"));
// this will write HTML to for instance the OutputStream of a HttpServletResponse-object
HtmlWriter.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();
Field Summary
public static final  byte[] BEGINCOMMENT    This is a possible HTML-tag. 
public static final  byte[] ENDCOMMENT    This is a possible HTML-tag. 
public static final  String NBSP    This is a possible HTML-tag. 
protected  Stack currentfont    This is the current font of the HTML. 
protected  Font standardfont    This is the standard font of the HTML. 
protected  String imagepath    This is a path for images. 
protected  int pageN    Stores the page number. 
protected  HeaderFooter header    This is the textual part of a header 
protected  HeaderFooter footer    This is the textual part of the footer 
protected  Properties markup    Store the markup properties of a MarkedObject. 
Fields inherited from com.lowagie.text.DocWriter:
NEWLINE,  TAB,  LT,  SPACE,  EQUALS,  QUOTE,  GT,  FORWARD,  pageSize,  document,  os,  open,  pause,  closeStream
Constructor:
 protected HtmlWriter(Document doc,
    OutputStream os) 
    Constructs a HtmlWriter.
    Parameters:
    doc - The Document that has to be written as HTML
    os - The OutputStream the writer has to write to.
Method from com.lowagie.text.html.HtmlWriter Summary:
add,   add,   close,   getInstance,   initFooter,   initHeader,   isOtherFont,   newPage,   open,   resetImagepath,   setFooter,   setHeader,   setImagepath,   setStandardFont,   write,   write,   writeComment,   writeCssProperty,   writeHeader,   writeJavaScript,   writeLink,   writeSection
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.html.HtmlWriter Detail:
 public boolean add(Element element) throws DocumentException 
    Signals that an Element was added to the Document.
 public boolean add(String string) 
    Signals that a String was added to the Document.
 public  void close() 
    Signals that the Document was closed and that no other Elements will be added.
 public static HtmlWriter getInstance(Document document,
    OutputStream os) 
    Gets an instance of the HtmlWriter.
 protected  void initFooter() 
    Adds the header to the top of the Document
 protected  void initHeader() 
    Adds the header to the top of the Document
 public boolean isOtherFont(Font font) 
    Checks if a given font is the same as the font that was last used.
 public boolean newPage() 
    Signals that an new page has to be started.
 public  void open() 
    Signals that the Document has been opened and that Elements can be added.

    The HEAD-section of the HTML-document is written.

 public  void resetImagepath() 
    Resets the imagepath.
 public  void setFooter(HeaderFooter footer) 
    Changes the footer of this document.
 public  void setHeader(HeaderFooter header) 
    Changes the header of this document.
 public  void setImagepath(String imagepath) 
    Sets the basepath for images.

    This is especially useful if you add images using a file, rather than an URL. In PDF there is no problem, since the images are added inline, but in HTML it is sometimes necessary to use a relative path or a special path to some images directory.

 public  void setStandardFont(Font standardfont) 
    Changes the standardfont.
 protected  void write(Element element,
    int indent) throws IOException 
    Writes the HTML representation of an element.
 protected  void write(Font font,
    Properties styleAttributes) throws IOException 
    Writes the representation of a Font.
 protected  void writeComment(String comment) throws IOException 
    Writes some comment.

    This method writes some comment.

 protected  void writeCssProperty(String prop,
    String value) throws IOException 
    Writes out a CSS property.
 protected  void writeHeader(Meta meta) throws IOException 
    Writes a Metatag in the header.
 protected  void writeJavaScript(Header header) throws IOException 
    Writes a JavaScript section or, if the markup attribute HtmlTags.URL is set, a JavaScript reference in the header.
 protected  void writeLink(Header header) throws IOException 
    Writes a link in the header.
 protected  void writeSection(Section section,
    int indent) throws IOException 
    Writes the HTML representation of a section.