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
Type | Name | Methods |
---|---|---|
float | Bottom Returns the lower left y-coordinate. | get |
float | BottomMargin Returns the bottom margin. | get |
string | HtmlStyleClass Gets the style class of the HTML body tag | get, set |
AccessibleElementId | ID | get, set |
bool | IsInline | get |
string | JavaScript_onLoad Gets the JavaScript onLoad command. | get, set |
string | JavaScript_onUnLoad Gets the JavaScript onUnLoad command. | get, set |
float | Left Returns the lower left x-coordinate. | get |
float | LeftMargin Returns the left margin. | get |
int | PageCount Sets the page number. | set |
int | PageNumber Returns the current page number. | get |
Rectangle | PageSize Gets the pagesize. | get |
float | Right Returns the upper right x-coordinate. | get |
float | RightMargin Return the right margin. | get |
PdfName | Role | get, set |
float | Top Returns the upper right y-coordinate. | get |
float | TopMargin Returns the top margin. | get |
Methods
Public methods
Returns | Name |
---|---|
bool | Add (IElement element)Adds an Element to the Document. |
bool | AddAuthor (string author)Adds the author to a Document. |
bool | AddCreationDate ()Adds the current date and time to a Document. |
bool | AddCreator (string creator)Adds the creator to a Document. |
void | AddDocListener (IDocListener listener)Adds a IDocListener to the Document. |
bool | AddHeader (string name, string content)Adds a user defined header to the document. |
bool | AddKeywords (string keywords)Adds the keywords to a Document. |
bool | AddLanguage (string language) |
bool | AddProducer ()Adds the producer to a Document. |
bool | AddSubject (string subject)Adds the subject to a Document. |
bool | AddTitle (string title)Adds the title to a Document. |
void | Close ()Closes the document. |
void | CloseDocument ()Closes the document. |
void | Dispose () |
PdfObject | GetAccessibleAttribute (PdfName key) |
Dictionary <PdfName , PdfObject > | GetAccessibleAttributes () |
float | GetBottom (float margin)Returns the lower left y-coordinate, considering a given margin. |
float | GetLeft (float margin)Returns the lower left x-coordinate considering a given margin. |
float | GetRight (float margin)Returns the upper right x-coordinate, considering a given margin. |
float | GetTop (float margin)Returns the upper right y-coordinate, considering a given margin. |
bool | IsMarginMirroring () |
bool | IsOpen ()Checks if the document is open. |
bool | NewPage ()Signals that an new page has to be started. |
void | Open ()Opens the document. |
void | OpenDocument ()Opens the document. |
void | RemoveIDocListener (IDocListener listener)Removes a IDocListener from the Document. |
void | ResetPageCount ()Sets the page number to 0. |
void | SetAccessibleAttribute (PdfName key, PdfObject value) |
bool | SetMarginMirroring (bool marginMirroring) |
bool | SetMarginMirroringTopBottom (bool marginMirroringTopBottom) |
bool | SetMargins (float marginLeft, float marginRight, float marginTop, float marginBottom)Sets the margins. |
bool | SetPageSize (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
-
IDocListener
-
IElementListener
IDisposable
-
IAccessibleElement
Constructors
Document [1/3]
public Document()
Summary
Constructs a new Document-object.
Document [2/3]
public Document(Rectangle pageSize)
Arguments
Type | Name | Description |
---|---|---|
Rectangle | pageSize | the pageSize |
Summary
Constructs a new Document-object.
Document [3/3]
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Arguments
Type | Name | Description |
---|---|---|
Rectangle | pageSize | the pageSize |
float | marginLeft | the margin on the left |
float | marginRight | the margin on the right |
float | marginTop | the margin on the top |
float | marginBottom | the margin on the bottom |
Summary
Constructs a new Document-object.
Methods
AddDocListener
public virtual void AddDocListener(IDocListener listener)
Arguments
Type | Name | Description |
---|---|---|
IDocListener | listener | the new IDocListener |
Summary
Adds a IDocListener to the Document.
RemoveIDocListener
public virtual void RemoveIDocListener(IDocListener listener)
Arguments
Type | Name | Description |
---|---|---|
IDocListener | listener | the IDocListener that has to be removed. |
Summary
Removes a IDocListener from the Document.
Add
public virtual bool Add(IElement element)
Arguments
Type | Name | Description |
---|---|---|
IElement | element | the Element to add |
Summary
Adds an Element to the Document.
Returns
true if the element was added, false if not
Open
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
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
public virtual bool SetPageSize(Rectangle pageSize)
Arguments
Type | Name | Description |
---|---|---|
Rectangle | pageSize | the new pagesize |
Summary
Sets the pagesize.
Returns
a bool
SetMargins
public virtual bool SetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Arguments
Type | Name | Description |
---|---|---|
float | marginLeft | the margin on the left |
float | marginRight | the margin on the right |
float | marginTop | the margin on the top |
float | marginBottom | the margin on the bottom |
Summary
Sets the margins.
Returns
NewPage
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
public virtual void ResetPageCount()
Summary
Sets the page number to 0.
Close
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
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
public virtual bool AddHeader(string name, string content)
Arguments
Type | Name | Description |
---|---|---|
string | name | the name of the header |
string | content | the content of the header |
Summary
Adds a user defined header to the document.
Returns
true if successful, false otherwise
AddTitle
public virtual bool AddTitle(string title)
Arguments
Type | Name | Description |
---|---|---|
string | title | the title |
Summary
Adds the title to a Document.
Returns
true if successful, false otherwise
AddSubject
public virtual bool AddSubject(string subject)
Arguments
Type | Name | Description |
---|---|---|
string | subject | the subject |
Summary
Adds the subject to a Document.
Returns
true if successful, false otherwise
AddKeywords
public virtual bool AddKeywords(string keywords)
Arguments
Type | Name | Description |
---|---|---|
string | keywords | keywords to add |
Summary
Adds the keywords to a Document.
Returns
true if successful, false otherwise
AddAuthor
public virtual bool AddAuthor(string author)
Arguments
Type | Name | Description |
---|---|---|
string | author | the name of the author |
Summary
Adds the author to a Document.
Returns
true if successful, false otherwise
AddCreator
public virtual bool AddCreator(string creator)
Arguments
Type | Name | Description |
---|---|---|
string | creator | the name of the creator |
Summary
Adds the creator to a Document.
Returns
true if successful, false otherwise
AddProducer
public virtual bool AddProducer()
Summary
Adds the producer to a Document.
Returns
true if successful, false otherwise
AddLanguage
public virtual bool AddLanguage(string language)
Arguments
Type | Name | Description |
---|---|---|
string | language |
AddCreationDate
public virtual bool AddCreationDate()
Summary
Adds the current date and time to a Document.
Returns
true if successful, false otherwise
GetLeft
public virtual float GetLeft(float margin)
Arguments
Type | Name | Description |
---|---|---|
float | margin | a margin |
Summary
Returns the lower left x-coordinate considering a given margin.
Returns
the lower left x-coordinate
GetRight
public virtual float GetRight(float margin)
Arguments
Type | Name | Description |
---|---|---|
float | margin | a margin |
Summary
Returns the upper right x-coordinate, considering a given margin.
Returns
the upper right x-coordinate
GetTop
public virtual float GetTop(float margin)
Arguments
Type | Name | Description |
---|---|---|
float | margin | a margin |
Summary
Returns the upper right y-coordinate, considering a given margin.
Returns
the upper right y-coordinate
GetBottom
public virtual float GetBottom(float margin)
Arguments
Type | Name | Description |
---|---|---|
float | margin | a margin |
Summary
Returns the lower left y-coordinate, considering a given margin.
Returns
the lower left y-coordinate
IsOpen
public virtual bool IsOpen()
Summary
Checks if the document is open.
Returns
true if the document is open
SetMarginMirroring
public virtual bool SetMarginMirroring(bool marginMirroring)
Arguments
Type | Name | Description |
---|---|---|
bool | marginMirroring |
SetMarginMirroringTopBottom
public virtual bool SetMarginMirroringTopBottom(bool marginMirroringTopBottom)
Arguments
Type | Name | Description |
---|---|---|
bool | marginMirroringTopBottom |
IsMarginMirroring
public virtual bool IsMarginMirroring()
Dispose
public virtual void Dispose()
GetAccessibleAttribute
public virtual PdfObject GetAccessibleAttribute(PdfName key)
Arguments
Type | Name | Description |
---|---|---|
PdfName | key |
SetAccessibleAttribute
public virtual void SetAccessibleAttribute(PdfName key, PdfObject value)
Arguments
GetAccessibleAttributes
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