Skip to main content
Skip table of contents

Document

Document Public class

Description

A generic Document class.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph iTextSharp.text
  iTextSharp.text.Document[[Document]]
  iTextSharp.text.IDocListener[[IDocListener]]
  class iTextSharp.text.IDocListener interfaceStyle;
  iTextSharp.text.IElementListener[[IElementListener]]
  class iTextSharp.text.IElementListener interfaceStyle;
  end
  subgraph System
System.IDisposable[[IDisposable]]
  end
  subgraph iTextSharp.text.pdf.interfaces
  iTextSharp.text.pdf.interfaces.IAccessibleElement[[IAccessibleElement]]
  class iTextSharp.text.pdf.interfaces.IAccessibleElement interfaceStyle;
  end
iTextSharp.text.IDocListener --> iTextSharp.text.Document
iTextSharp.text.IElementListener --> iTextSharp.text.IDocListener
System.IDisposable --> iTextSharp.text.IDocListener
iTextSharp.text.pdf.interfaces.IAccessibleElement --> iTextSharp.text.Document

Members

Properties

Public properties
TypeNameMethods
floatBottom
Returns the lower left y-coordinate.
get
floatBottomMargin
Returns the bottom margin.
get
stringHtmlStyleClass
Gets the style class of the HTML body tag
get, set
AccessibleElementIdIDget, set
boolIsInlineget
stringJavaScript_onLoad
Gets the JavaScript onLoad command.
get, set
stringJavaScript_onUnLoad
Gets the JavaScript onUnLoad command.
get, set
floatLeft
Returns the lower left x-coordinate.
get
floatLeftMargin
Returns the left margin.
get
intPageCount
Sets the page number.
set
intPageNumber
Returns the current page number.
get
RectanglePageSize
Gets the pagesize.
get
floatRight
Returns the upper right x-coordinate.
get
floatRightMargin
Return the right margin.
get
PdfNameRoleget, set
floatTop
Returns the upper right y-coordinate.
get
floatTopMargin
Returns the top margin.
get

Methods

Public methods
ReturnsName
boolAdd(IElement element)
Adds an Element to the Document.
boolAddAuthor(string author)
Adds the author to a Document.
boolAddCreationDate()
Adds the current date and time to a Document.
boolAddCreator(string creator)
Adds the creator to a Document.
voidAddDocListener(IDocListener listener)
Adds a IDocListener to the Document.
boolAddHeader(string name, string content)
Adds a user defined header to the document.
boolAddKeywords(string keywords)
Adds the keywords to a Document.
boolAddLanguage(string language)
boolAddProducer()
Adds the producer to a Document.
boolAddSubject(string subject)
Adds the subject to a Document.
boolAddTitle(string title)
Adds the title to a Document.
voidClose()
Closes the document.
voidCloseDocument()
Closes the document.
voidDispose()
PdfObjectGetAccessibleAttribute(PdfName key)
Dictionary<PdfName, PdfObject>GetAccessibleAttributes()
floatGetBottom(float margin)
Returns the lower left y-coordinate, considering a given margin.
floatGetLeft(float margin)
Returns the lower left x-coordinate considering a given margin.
floatGetRight(float margin)
Returns the upper right x-coordinate, considering a given margin.
floatGetTop(float margin)
Returns the upper right y-coordinate, considering a given margin.
boolIsMarginMirroring()
boolIsOpen()
Checks if the document is open.
boolNewPage()
Signals that an new page has to be started.
voidOpen()
Opens the document.
voidOpenDocument()
Opens the document.
voidRemoveIDocListener(IDocListener listener)
Removes a IDocListener from the Document.
voidResetPageCount()
Sets the page number to 0.
voidSetAccessibleAttribute(PdfName key, PdfObject value)
boolSetMarginMirroring(bool marginMirroring)
boolSetMarginMirroringTopBottom(bool marginMirroringTopBottom)
boolSetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the margins.
boolSetPageSize(Rectangle pageSize)
Sets the pagesize.

Details

Summary

A generic Document class.

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.

Example


            // creation of the document with a certain size and certain margins
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
            try {
                // creation of the different writers
                HtmlWriter.GetInstance(document, System.out);
                PdfWriter.GetInstance(document, new FileOutputStream("text.pdf"));
                // we add some meta information to the document
                document.AddAuthor("Bruno Lowagie");
                document.AddSubject("This is the result of a Test.");
                
                // 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);
                document.SetHeader(header);
                document.SetFooter(footer);
                // we open the document for writing
                document.Open();
                document.Add(new Paragraph("Hello world"));
            }
            catch (DocumentException de) {
                Console.Error.WriteLine(de.Message);
            }
            document.Close();

Inheritance

Constructors

Document [1/3]

Source code

public Document()
Summary

Constructs a new Document-object.

Document [2/3]

Source code

public Document(Rectangle pageSize)
Arguments
TypeNameDescription
RectanglepageSizethe pageSize
Summary

Constructs a new Document-object.

Document [3/3]

Source code

public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Arguments
TypeNameDescription
RectanglepageSizethe pageSize
floatmarginLeftthe margin on the left
floatmarginRightthe margin on the right
floatmarginTopthe margin on the top
floatmarginBottomthe margin on the bottom
Summary

Constructs a new Document-object.

Methods

AddDocListener

Source code

public virtual void AddDocListener(IDocListener listener)
Arguments
TypeNameDescription
IDocListenerlistenerthe new IDocListener
Summary

Adds a IDocListener to the Document.

RemoveIDocListener

Source code

public virtual void RemoveIDocListener(IDocListener listener)
Arguments
TypeNameDescription
IDocListenerlistenerthe IDocListener that has to be removed.
Summary

Removes a IDocListener from the Document.

Add

Source code

public virtual bool Add(IElement element)
Arguments
TypeNameDescription
IElementelementthe Element to add
Summary

Adds an Element to the Document.

Returns

true if the element was added, false if not

Open

Source code

public virtual void Open()
Summary

Opens the document.

Remarks

Once the document is opened, you can't write any Header- or Meta-information anymore. You have to open the document before you can begin to add content to the body of the document.

OpenDocument

Source code

public virtual void OpenDocument()
Summary

Opens the document.

Remarks

Version for languages that are not case-dependant. Once the document is opened, you can't write any Header- or Meta-information anymore. You have to open the document before you can begin to add content to the body of the document.

SetPageSize

Source code

public virtual bool SetPageSize(Rectangle pageSize)
Arguments
TypeNameDescription
RectanglepageSizethe new pagesize
Summary

Sets the pagesize.

Returns

a bool

SetMargins

Source code

public virtual bool SetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Arguments
TypeNameDescription
floatmarginLeftthe margin on the left
floatmarginRightthe margin on the right
floatmarginTopthe margin on the top
floatmarginBottomthe margin on the bottom
Summary

Sets the margins.

Returns
NewPage

Source code

public virtual bool NewPage()
Summary

Signals that an new page has to be started.

Returns

true if the page was added, false if not.

ResetPageCount

Source code

public virtual void ResetPageCount()
Summary

Sets the page number to 0.

Close

Source code

public virtual void Close()
Summary

Closes the document.

Remarks

Once all the content has been written in the body, you have to close the body. After that nothing can be written to the body anymore.

CloseDocument

Source code

public virtual void CloseDocument()
Summary

Closes the document.

Remarks

Version for languages that are not case-dependant. Once all the content has been written in the body, you have to close the body. After that nothing can be written to the body anymore.

AddHeader

Source code

public virtual bool AddHeader(string name, string content)
Arguments
TypeNameDescription
stringnamethe name of the header
stringcontentthe content of the header
Summary

Adds a user defined header to the document.

Returns

true if successful, false otherwise

AddTitle

Source code

public virtual bool AddTitle(string title)
Arguments
TypeNameDescription
stringtitlethe title
Summary

Adds the title to a Document.

Returns

true if successful, false otherwise

AddSubject

Source code

public virtual bool AddSubject(string subject)
Arguments
TypeNameDescription
stringsubjectthe subject
Summary

Adds the subject to a Document.

Returns

true if successful, false otherwise

AddKeywords

Source code

public virtual bool AddKeywords(string keywords)
Arguments
TypeNameDescription
stringkeywordskeywords to add
Summary

Adds the keywords to a Document.

Returns

true if successful, false otherwise

AddAuthor

Source code

public virtual bool AddAuthor(string author)
Arguments
TypeNameDescription
stringauthorthe name of the author
Summary

Adds the author to a Document.

Returns

true if successful, false otherwise

AddCreator

Source code

public virtual bool AddCreator(string creator)
Arguments
TypeNameDescription
stringcreatorthe name of the creator
Summary

Adds the creator to a Document.

Returns

true if successful, false otherwise

AddProducer

Source code

public virtual bool AddProducer()
Summary

Adds the producer to a Document.

Returns

true if successful, false otherwise

AddLanguage

Source code

public virtual bool AddLanguage(string language)
Arguments
TypeNameDescription
stringlanguage
AddCreationDate

Source code

public virtual bool AddCreationDate()
Summary

Adds the current date and time to a Document.

Returns

true if successful, false otherwise

GetLeft

Source code

public virtual float GetLeft(float margin)
Arguments
TypeNameDescription
floatmargina margin
Summary

Returns the lower left x-coordinate considering a given margin.

Returns

the lower left x-coordinate

GetRight

Source code

public virtual float GetRight(float margin)
Arguments
TypeNameDescription
floatmargina margin
Summary

Returns the upper right x-coordinate, considering a given margin.

Returns

the upper right x-coordinate

GetTop

Source code

public virtual float GetTop(float margin)
Arguments
TypeNameDescription
floatmargina margin
Summary

Returns the upper right y-coordinate, considering a given margin.

Returns

the upper right y-coordinate

GetBottom

Source code

public virtual float GetBottom(float margin)
Arguments
TypeNameDescription
floatmargina margin
Summary

Returns the lower left y-coordinate, considering a given margin.

Returns

the lower left y-coordinate

IsOpen

Source code

public virtual bool IsOpen()
Summary

Checks if the document is open.

Returns

true if the document is open

SetMarginMirroring

Source code

public virtual bool SetMarginMirroring(bool marginMirroring)
Arguments
TypeNameDescription
boolmarginMirroring
SetMarginMirroringTopBottom

Source code

public virtual bool SetMarginMirroringTopBottom(bool marginMirroringTopBottom)
Arguments
TypeNameDescription
boolmarginMirroringTopBottom
IsMarginMirroring

Source code

public virtual bool IsMarginMirroring()
Dispose

Source code

public virtual void Dispose()
GetAccessibleAttribute

Source code

public virtual PdfObject GetAccessibleAttribute(PdfName key)
Arguments
TypeNameDescription
PdfNamekey
SetAccessibleAttribute

Source code

public virtual void SetAccessibleAttribute(PdfName key, PdfObject value)
Arguments
TypeNameDescription
PdfNamekey
PdfObjectvalue
GetAccessibleAttributes

Source code

public virtual Dictionary<PdfName, PdfObject> GetAccessibleAttributes()

Properties

PageCount
public virtual int PageCount { set; }
Summary

Sets the page number.

Value

an int

PageNumber
public virtual int PageNumber { get; }
Summary

Returns the current page number.

Value

an int

LeftMargin
public virtual float LeftMargin { get; }
Summary

Returns the left margin.

Value

the left margin

RightMargin
public virtual float RightMargin { get; }
Summary

Return the right margin.

Value

the right margin

TopMargin
public virtual float TopMargin { get; }
Summary

Returns the top margin.

Value

the top margin

BottomMargin
public virtual float BottomMargin { get; }
Summary

Returns the bottom margin.

Value

the bottom margin

Left
public virtual float Left { get; }
Summary

Returns the lower left x-coordinate.

Value

the lower left x-coordinate

Right
public virtual float Right { get; }
Summary

Returns the upper right x-coordinate.

Value

the upper right x-coordinate.

Top
public virtual float Top { get; }
Summary

Returns the upper right y-coordinate.

Value

the upper right y-coordinate.

Bottom
public virtual float Bottom { get; }
Summary

Returns the lower left y-coordinate.

Value

the lower left y-coordinate.

PageSize
public virtual Rectangle PageSize { get; }
Summary

Gets the pagesize.

Value

the page size

JavaScript_onLoad
public virtual string JavaScript_onLoad { get; set; }
Summary

Gets the JavaScript onLoad command.

Value

the JavaScript onLoad command.

JavaScript_onUnLoad
public virtual string JavaScript_onUnLoad { get; set; }
Summary

Gets the JavaScript onUnLoad command.

Value

the JavaScript onUnLoad command

HtmlStyleClass
public virtual string HtmlStyleClass { get; set; }
Summary

Gets the style class of the HTML body tag

Value

the style class of the HTML body tag

Role
public virtual PdfName Role { get; set; }
ID
public virtual AccessibleElementId ID { get; set; }
IsInline
public virtual bool IsInline { get; }

Generated with ModularDoc

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.