A generic Document class.

Namespace: iTextSharp.text
Assembly: ITextSharp (in ITextSharp.dll) Version: 4.1.6.0

Syntax

C#
public class Document : IDocListener, IElementListener
Visual Basic
Public Class Document _
	Implements IDocListener, IElementListener
Visual C++
public ref class Document : IDocListener, 
	IElementListener

Remarks

All kinds of Text-elements can be added to a HTMLDocument. The Document signals all the listeners when an element has been added.

Once a document is created you can add some meta information. You can also set the headers/footers. You have to open the document before you can write content. You can only write content (no more meta-formation!) once a document is opened. When you change the header/footer on a certain page, this will be effective starting on the next page. Ater closing the document, every listener (as well as its OutputStream) is closed too.

Examples

CopyC#
// creation of the document with a certain size and certain margins
<strong>Document document = new Document(PageSize.A4, 50, 50, 50, 50);</strong>
try {
    // creation of the different writers
    HtmlWriter.GetInstance(<strong>document</strong>, System.out);
    PdfWriter.GetInstance(<strong>document</strong>, new FileOutputStream("text.pdf"));
    // we add some meta information to the document
    <strong>document.AddAuthor("Bruno Lowagie");
    document.AddSubject("This is the result of a Test.");</strong>

    // we define a header and a footer
    HeaderFooter header = new HeaderFooter(new Phrase("This is a header."), false);
    HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));
    footer.SetAlignment(Element.ALIGN_CENTER);
    <strong>document.SetHeader(header);
    document.SetFooter(footer);</strong>
    // we open the document for writing
    <strong>document.Open();
    document.Add(new Paragraph("Hello world"));</strong>
}
catch (DocumentException de) {
    Console.Error.WriteLine(de.Message);
}
<strong>document.Close();</strong>

Inheritance Hierarchy

System..::..Object
  iTextSharp.text..::..Document
    iTextSharp.text.pdf..::..PdfDocument

See Also