Table of Contents

Class PdfDocument

Namespace
iTextSharp.text.pdf
Assembly
iTextSharp.LGPLv2.Core.dll

PdfDocument is the class that is used by PdfWriter to translate a Document into a PDF with different pages. A PdfDocument always listens to a Document and adds the Pdf representation of every Element that is added to the Document . @see com.lowagie.text.Document @see com.lowagie.text.DocListener @see PdfWriter

public class PdfDocument : Document, IDocListener, IElementListener, IDisposable
Inheritance
PdfDocument
Implements
Inherited Members

Fields

AdditionalActions

protected PdfDictionary AdditionalActions

Field Value

PdfDictionary

Alignment

This represents the current alignment of the PDF Elements.

protected int Alignment

Field Value

int

AnchorAction

The current active PdfAction when processing an Anchor .

protected PdfAction AnchorAction

Field Value

PdfAction

BoxSize

This is the size of the several boxes that will be used in the next page.

protected INullValueDictionary<string, PdfRectangle> BoxSize

Field Value

INullValueDictionary<string, PdfRectangle>

CurrentOutline

This is the current PdfOutline in the hierarchy of outlines.

protected PdfOutline CurrentOutline

Field Value

PdfOutline

DocumentFileAttachment

protected INullValueDictionary<string, PdfObject> DocumentFileAttachment

Field Value

INullValueDictionary<string, PdfObject>

DocumentLevelJs

protected INullValueDictionary<string, PdfObject> DocumentLevelJs

Field Value

INullValueDictionary<string, PdfObject>

FirstPageEvent

Signals that OnOpenDocument should be called.

protected bool FirstPageEvent

Field Value

bool

Graphics

This is the PdfContentByte object, containing the borders and other Graphics.

protected PdfContentByte Graphics

Field Value

PdfContentByte

ImageEnd

This is the position where the image ends.

protected float ImageEnd

Field Value

float

ImageWait

This is the image that could not be shown on a previous page.

protected Image ImageWait

Field Value

Image

IsSectionTitle

Signals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph). @since 2.1.2

protected bool IsSectionTitle

Field Value

bool

LastElementType

Holds the type of the last element, that has been added to the document.

protected int LastElementType

Field Value

int

LeadingCount

Signals that the current leading has to be subtracted from a YMark object. @since 2.1.2

protected int LeadingCount

Field Value

int

Line

The line that is currently being written.

protected PdfLine Line

Field Value

PdfLine

Lines

The lines that are written until now.

protected IList<PdfLine> Lines

Field Value

IList<PdfLine>

LocalDestinations

Stores the destinations keyed by name. Value is Object[]{PdfAction,PdfIndirectReference,PdfDestintion} .

protected OrderedTree LocalDestinations

Field Value

OrderedTree

MarkPoint

protected int MarkPoint

Field Value

int

NextMarginBottom

margin in y direction starting from the bottom. Will be valid in the next page

protected float NextMarginBottom

Field Value

float

NextMarginLeft

margin in x direction starting from the left. Will be valid in the next page

protected float NextMarginLeft

Field Value

float

NextMarginRight

margin in x direction starting from the right. Will be valid in the next page

protected float NextMarginRight

Field Value

float

NextMarginTop

margin in y direction starting from the top. Will be valid in the next page

protected float NextMarginTop

Field Value

float

NextPageSize

This is the size of the next page.

protected Rectangle NextPageSize

Field Value

Rectangle

OpenActionAction

protected PdfAction OpenActionAction

Field Value

PdfAction

OpenActionName

protected string OpenActionName

Field Value

string

PageAa

protected PdfDictionary PageAa

Field Value

PdfDictionary

Text

This is the PdfContentByte object, containing the text.

protected PdfContentByte Text

Field Value

PdfContentByte

TextEmptySize

protected int TextEmptySize

Field Value

int

ThisBoxSize

[U1] page sizes

protected INullValueDictionary<string, PdfRectangle> ThisBoxSize

Field Value

INullValueDictionary<string, PdfRectangle>

Thumb

protected PdfIndirectReference Thumb

Field Value

PdfIndirectReference

Writer

The PdfWriter .

protected PdfWriter Writer

Field Value

PdfWriter

collection

protected PdfCollection collection

Field Value

PdfCollection

duration

The duration of the page

protected int duration

Field Value

int

indentation

protected PdfDocument.Indentation indentation

Field Value

PdfDocument.Indentation

info

some meta information about the Document.

protected PdfDocument.PdfInfo info

Field Value

PdfDocument.PdfInfo

leading

This represents the leading of the lines.

protected float leading

Field Value

float

pageEmpty

This checks if the page is empty.

protected bool pageEmpty

Field Value

bool

pageLabels

protected PdfPageLabels pageLabels

Field Value

PdfPageLabels

pageResources

This are the page resources of the current Page.

protected PageResources pageResources

Field Value

PageResources

rootOutline

This is the root outline of the document.

protected PdfOutline rootOutline

Field Value

PdfOutline

strictImageSequence

Holds value of property strictImageSequence.

protected bool strictImageSequence

Field Value

bool

transition

The page transition

protected PdfTransition transition

Field Value

PdfTransition

viewerPreferences

Contains the Viewer preferences of this PDF document.

protected PdfViewerPreferencesImp viewerPreferences

Field Value

PdfViewerPreferencesImp

xmpMetadata

[L3] DocListener interface

protected byte[] xmpMetadata

Field Value

byte[]

Properties

AcroForm

[C8] AcroForm

public PdfAcroForm AcroForm { get; }

Property Value

PdfAcroForm

the PdfAcroform object of the PdfDocument

Collection

Sets the collection dictionary.

public PdfCollection Collection { set; }

Property Value

PdfCollection

CurrentHeight

This is the current height of the document.

public float CurrentHeight { get; }

Property Value

float

Changes the footer of this document.

public override HeaderFooter Footer { set; }

Property Value

HeaderFooter

Header

Changes the header of this document.

public override HeaderFooter Header { set; }

Property Value

HeaderFooter

IndentBottom

protected float IndentBottom { get; }

Property Value

float

IndentLeft

protected float IndentLeft { get; }

Property Value

float

IndentRight

protected float IndentRight { get; }

Property Value

float

IndentTop

protected float IndentTop { get; }

Property Value

float

Leading

[L0] ElementListener interface

public float Leading { get; set; }

Property Value

float

the current leading

PageCount

Sets the page number.

public override int PageCount { set; }

Property Value

int

RootOutline

Gets the root outline. All the outlines must be created with a parent. The first level is created with this outline.

public PdfOutline RootOutline { get; }

Property Value

PdfOutline

the root outline

XmpMetadata

Use this method to set the XMP Metadata.

public byte[] XmpMetadata { set; }

Property Value

byte[]

Methods

Add(IElement)

LISTENER METHODS START

public override bool Add(IElement element)

Parameters

element IElement

the element to add

Returns

bool

true if the element was added, false if not.

Add(Image)

Adds an image to the document. @throws PdfException on error @throws DocumentException on error

protected void Add(Image image)

Parameters

image Image

the Image to add

AddSpacing(float, float, Font)

Gets the indentation on the left side.

protected void AddSpacing(float extraspace, float oldleading, Font f)

Parameters

extraspace float
oldleading float
f Font

AnalyzeRow(IList<IList<PdfCell>>, RenderingContext)

protected void AnalyzeRow(IList<IList<PdfCell>> rows, PdfDocument.RenderingContext ctx)

Parameters

rows IList<IList<PdfCell>>
ctx PdfDocument.RenderingContext

CarriageReturn()

protected void CarriageReturn()

ClearTextWrap()

Method added by Pelikan Stephan @see com.lowagie.text.DocListener#clearTextWrap()

public void ClearTextWrap()

Close()

Closes the document. 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.

public override void Close()

ConsumeRowspan(IList<PdfCell>, RenderingContext)

protected static void ConsumeRowspan(IList<PdfCell> row, PdfDocument.RenderingContext ctx)

Parameters

row IList<PdfCell>
ctx PdfDocument.RenderingContext

DoFooter()

[M5] header/footer

protected void DoFooter()

DoHeader()

protected void DoHeader()

EnsureNewLine()

If the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added. @throws DocumentException on error

protected void EnsureNewLine()

ExtractRows(IList<PdfCell>, RenderingContext)

protected static IList<IList<PdfCell>> ExtractRows(IList<PdfCell> cells, PdfDocument.RenderingContext ctx)

Parameters

cells IList<PdfCell>
ctx PdfDocument.RenderingContext

Returns

IList<IList<PdfCell>>

FlushLines()

Writes all the lines to the text-object. @throws DocumentException on error

protected float FlushLines()

Returns

float

the displacement that was caused

GetVerticalPosition(bool)

Gets the current vertical page position. for elements that do not terminate the lines they've started because those lines will get terminated.

public float GetVerticalPosition(bool ensureNewLine)

Parameters

ensureNewLine bool

Tells whether a new line shall be enforced. This may cause side effects

Returns

float

The current vertical page position.

InitPage()

protected void InitPage()

MayBeRemoved(IList<PdfCell>)

protected static bool MayBeRemoved(IList<PdfCell> row)

Parameters

row IList<PdfCell>

Returns

bool

NewLine()

protected void NewLine()

NewPage()

[L2] DocListener interface

public override bool NewPage()

Returns

bool

a bool

Open()

Opens the document. You have to open the document before you can begin to add content to the body of the document.

public override void Open()

RenderCells(RenderingContext, IList<PdfCell>, bool)

protected void RenderCells(PdfDocument.RenderingContext ctx, IList<PdfCell> cells, bool hasToFit)

Parameters

ctx PdfDocument.RenderingContext
cells IList<PdfCell>
hasToFit bool

ResetFooter()

Resets the footer of this document.

public override void ResetFooter()

ResetHeader()

Resets the header of this document.

public override void ResetHeader()

ResetPageCount()

Sets the page number to 0.

public override void ResetPageCount()

SetMarginMirroring(bool)

@see com.lowagie.text.DocListener#setMarginMirroring(bool)

public override bool SetMarginMirroring(bool marginMirroring)

Parameters

marginMirroring bool

Returns

bool

SetMarginMirroringTopBottom(bool)

[L6] DocListener interface

public override bool SetMarginMirroringTopBottom(bool marginMirroringTopBottom)

Parameters

marginMirroringTopBottom bool

Returns

bool

SetMargins(float, float, float, float)

Sets the margins.

public override bool SetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)

Parameters

marginLeft float

the margin on the left

marginRight float

the margin on the right

marginTop float

the margin on the top

marginBottom float

the margin on the bottom

Returns

bool

a bool

SetNewPageSizeAndMargins()

protected void SetNewPageSizeAndMargins()

SetPageSize(Rectangle)

Sets the pagesize.

public override bool SetPageSize(Rectangle pageSize)

Parameters

pageSize Rectangle

the new pagesize

Returns

bool

true if the page size was set