Table of Contents

Class Document

Namespace
iText.Layout
Assembly
itext.layout.dll

Document is the default root element when creating a self-sufficient PDF.

public class Document : RootElement<Document>, IPropertyContainer, IDisposable
Inheritance
Document
Implements
Inherited Members

Remarks

Document is the default root element when creating a self-sufficient PDF. It mainly operates high-level operations e.g. setting page size and rotation, adding elements, and writing text at specific coordinates. It has no knowledge of the actual PDF concepts and syntax.

A Document 's rendering behavior can be modified by extending DocumentRenderer and setting an instance of this newly created with SetRenderer(DocumentRenderer).

Constructors

Document(PdfDocument)

Creates a document from a PdfDocument.

public Document(PdfDocument pdfDoc)

Parameters

pdfDoc PdfDocument

the in-memory representation of the PDF document

Remarks

Creates a document from a PdfDocument . Initializes the first page with the PdfDocument 's current default PageSize.

Document(PdfDocument, PageSize)

Creates a document from a PdfDocument with a manually set PageSize.

public Document(PdfDocument pdfDoc, PageSize pageSize)

Parameters

pdfDoc PdfDocument

the in-memory representation of the PDF document

pageSize PageSize

the page size

Document(PdfDocument, PageSize, bool)

Creates a document from a PdfDocument with a manually set PageSize.

public Document(PdfDocument pdfDoc, PageSize pageSize, bool immediateFlush)

Parameters

pdfDoc PdfDocument

the in-memory representation of the PDF document

pageSize PageSize

the page size

immediateFlush bool

if true, write pages and page-related instructions to the PdfDocument as soon as possible.

Methods

Add(AreaBreak)

Terminates the current element, usually a page.

public virtual Document Add(AreaBreak areaBreak)

Parameters

areaBreak AreaBreak

an AreaBreak , optionally with a specified size

Returns

Document

this element

Remarks

Terminates the current element, usually a page. Sets the next element to be the size specified in the argument.

Add(IBlockElement)

public override Document Add(IBlockElement element)

Parameters

element IBlockElement

Returns

Document

CheckClosingStatus()

Checks whether a method is invoked at the closed document

protected virtual void CheckClosingStatus()

Close()

Closes the document and associated PdfDocument.

public override void Close()

EnsureRootRendererNotNull()

protected override RootRenderer EnsureRootRendererNotNull()

Returns

RootRenderer

Flush()

Forces all registered renderers (including child element renderers) to flush their contents to the content stream.

public virtual void Flush()

GetBottomMargin()

Gets the bottom margin, measured in points

public virtual float GetBottomMargin()

Returns

float

a float containing the bottom margin value

GetDefaultProperty<T1>(int)

public override T1 GetDefaultProperty<T1>(int property)

Parameters

property int

Returns

T1

Type Parameters

T1

GetLeftMargin()

Gets the left margin, measured in points

public virtual float GetLeftMargin()

Returns

float

a float containing the left margin value

GetPageEffectiveArea(PageSize)

Returns the area that will actually be used to write on the page, given the current margins.

public virtual Rectangle GetPageEffectiveArea(PageSize pageSize)

Parameters

pageSize PageSize

the size of the page to

Returns

Rectangle

a Rectangle with the required dimensions and origin point

Remarks

Returns the area that will actually be used to write on the page, given the current margins. Does not have any side effects on the document.

GetPdfDocument()

Gets PDF document.

public virtual PdfDocument GetPdfDocument()

Returns

PdfDocument

the in-memory representation of the PDF document

GetRightMargin()

Gets the right margin, measured in points

public virtual float GetRightMargin()

Returns

float

a float containing the right margin value

GetTopMargin()

Gets the top margin, measured in points

public virtual float GetTopMargin()

Returns

float

a float containing the top margin value

Relayout()

Performs an entire recalculation of the document flow, taking into account all its current child elements.

public virtual void Relayout()

Remarks

Performs an entire recalculation of the document flow, taking into account all its current child elements. May become very resource-intensive for large documents.

Do not use when you have set immediateFlush to true.

SetBottomMargin(float)

Sets the bottom margin, measured in points

public virtual void SetBottomMargin(float bottomMargin)

Parameters

bottomMargin float

a float containing the new bottom margin value

SetLeftMargin(float)

Sets the left margin, measured in points

public virtual void SetLeftMargin(float leftMargin)

Parameters

leftMargin float

a float containing the new left margin value

SetMargins(float, float, float, float)

Convenience method to set all margins with one method.

public virtual void SetMargins(float topMargin, float rightMargin, float bottomMargin, float leftMargin)

Parameters

topMargin float

the upper margin

rightMargin float

the right margin

bottomMargin float

the lower margin

leftMargin float

the left margin

SetRenderer(DocumentRenderer)

Changes the DocumentRenderer at runtime.

public virtual void SetRenderer(DocumentRenderer documentRenderer)

Parameters

documentRenderer DocumentRenderer

the DocumentRenderer to set

Remarks

Changes the DocumentRenderer at runtime. Use this to customize the Document's IRenderer behavior.

SetRightMargin(float)

Sets the right margin, measured in points

public virtual void SetRightMargin(float rightMargin)

Parameters

rightMargin float

a float containing the new right margin value

SetTopMargin(float)

Sets the top margin, measured in points

public virtual void SetTopMargin(float topMargin)

Parameters

topMargin float

a float containing the new top margin value