Class HtmlWriter
- Namespace
- iTextSharp.text.html
- Assembly
- iTextSharp.LGPLv2.Core.dll
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 Stream 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 Stream 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 Stream 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();
public class HtmlWriter : DocWriter, IDocListener, IElementListener, IDisposable
- Inheritance
-
HtmlWriter
- Implements
- Inherited Members
Constructors
HtmlWriter(Document, Stream)
constructor
protected HtmlWriter(Document doc, Stream os)
Parameters
doc
DocumentThe Document that has to be written as HTML
os
StreamThe Stream the writer has to write to.
Fields
Begincomment
This is a possible HTML-tag.
public static byte[] Begincomment
Field Value
- byte[]
Currentfont
membervariables
protected Stack<Font> Currentfont
Field Value
Endcomment
This is a possible HTML-tag.
public static byte[] Endcomment
Field Value
- byte[]
Imagepath
This is a path for images.
protected string Imagepath
Field Value
Markup
Store the markup properties of a MarkedObject.
protected Properties Markup
Field Value
NBSP
static membervariables (tags)
public const string NBSP = " "
Field Value
PageN
Stores the page number.
protected int PageN
Field Value
Standardfont
This is the standard font of the HTML.
protected Font Standardfont
Field Value
footer
This is the textual part of the footer
protected HeaderFooter footer
Field Value
header
This is the textual part of a header
protected HeaderFooter header
Field Value
Methods
Add(string)
public bool Add(string str)
Parameters
str
string
Returns
Add(IElement)
implementation of the DocListener methods
public override bool Add(IElement element)
Parameters
element
IElement
Returns
- bool
true if this action succeeded, false if not.
Close()
Signals that the Document was closed and that no other Elements will be added.
public override void Close()
GetInstance(Document, Stream)
get an instance of the HtmlWriter
public static HtmlWriter GetInstance(Document document, Stream os)
Parameters
document
DocumentThe Document that has to be written
os
StreamThe Stream the writer has to write to.
Returns
- HtmlWriter
a new HtmlWriter
InitFooter()
protected void InitFooter()
InitHeader()
protected void InitHeader()
IsOtherFont(Font)
public bool IsOtherFont(Font font)
Parameters
font
Font
Returns
NewPage()
public override bool NewPage()
Returns
Open()
Signals that an Element was added to the Document . @throws DocumentException when a document isn't open yet, or has been closed
public override void Open()
ResetImagepath()
Signals that the Document was closed and that no other Elements will be added.
public void ResetImagepath()
SetFooter(HeaderFooter)
public void SetFooter(HeaderFooter footer)
Parameters
footer
HeaderFooter
SetHeader(HeaderFooter)
public void SetHeader(HeaderFooter header)
Parameters
header
HeaderFooter
SetImagepath(string)
public void SetImagepath(string imagepath)
Parameters
imagepath
string
SetStandardFont(Font)
public void SetStandardFont(Font standardFont)
Parameters
standardFont
Font
Write(Font, Properties)
protected void Write(Font font, Properties styleAttributes)
Parameters
font
FontstyleAttributes
Properties
Write(IElement, int)
Writes a Metatag in the header. @throws IOException
protected void Write(IElement element, int indent)
Parameters
WriteComment(string)
protected void WriteComment(string comment)
Parameters
comment
string
WriteCssProperty(string, string)
Writes out a CSS property.
protected void WriteCssProperty(string prop, string value)
Parameters
WriteHeader(Meta)
protected void WriteHeader(Meta meta)
Parameters
meta
Meta
WriteJavaScript(Header)
Writes a link in the header. @throws IOException
protected void WriteJavaScript(Header header)
Parameters
header
Headerthe element that has to be written
WriteLink(Header)
protected void WriteLink(Header header)
Parameters
header
Header
WriteSection(Section, int)
Writes the HTML representation of a section.
protected void WriteSection(Section section, int indent)