iText 9.7.0 API
iText.Layout.Document Class Reference

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

Inheritance diagram for iText.Layout.Document:
iText.Layout.RootElement< iText.Layout.Document >

Public Member Functions

  Document (PdfDocument pdfDoc)
  Creates a document from a iText.Kernel.Pdf.PdfDocument. More...
 
  Document (PdfDocument pdfDoc, PageSize pageSize)
  Creates a document from a iText.Kernel.Pdf.PdfDocument with a manually set iText.Kernel.Geom.PageSize. More...
 
  Document (PdfDocument pdfDoc, PageSize pageSize, bool immediateFlush)
  Creates a document from a iText.Kernel.Pdf.PdfDocument with a manually set iText.Kernel.Geom.PageSize. More...
 
override void  Close ()
  Closes the document and associated PdfDocument. More...
 
virtual iText.Layout.Document  Add (AreaBreak areaBreak)
  Terminates the current element, usually a page. More...
 
virtual iText.Layout.Document  Add (SectionBreak sectionBreak)
  Terminates the current page if it's not the first one in the document. More...
 
override iText.Layout.Document  Add (IBlockElement element)
 
virtual PdfDocument  GetPdfDocument ()
  Gets PDF document. More...
 
virtual void  SetRenderer (DocumentRenderer documentRenderer)
  Changes the iText.Layout.Renderer.DocumentRenderer at runtime. More...
 
virtual void  Flush ()
  Forces all registered renderers (including child element renderers) to flush their contents to the content stream. More...
 
virtual void  Relayout ()
  Performs an entire recalculation of the document flow, taking into account all its current child elements. More...
 
virtual float  GetLeftMargin ()
  Gets the left margin, measured in points More...
 
virtual void  SetLeftMargin (float leftMargin)
  Sets the left margin, measured in points More...
 
virtual float  GetRightMargin ()
  Gets the right margin, measured in points More...
 
virtual void  SetRightMargin (float rightMargin)
  Sets the right margin, measured in points More...
 
virtual float  GetTopMargin ()
  Gets the top margin, measured in points More...
 
virtual void  SetTopMargin (float topMargin)
  Sets the top margin, measured in points More...
 
virtual float  GetBottomMargin ()
  Gets the bottom margin, measured in points More...
 
virtual void  SetBottomMargin (float bottomMargin)
  Sets the bottom margin, measured in points More...
 
virtual void  SetMargins (float topMargin, float rightMargin, float bottomMargin, float leftMargin)
  Convenience method to set all margins with one method. More...
 
virtual PageMarginBoxes  GetPageMargins (int pageNumber)
  Gets page margins by specified page number. More...
 
virtual iText.Layout.Document  SetPageMargins (int pageNumber, PageMarginBoxes margins)
  Sets page margins for page with provided number. More...
 
virtual iText.Layout.Document  SetPageMargins (Predicate< int > condition, PageMarginBoxes margins)
  Sets page margins for page based on provided condition for page number. More...
 
virtual iText.Layout.Document  SetPageMargins (Func< int, PageMarginBoxes > function)
  Sets page margins for page based on provided function for page number. More...
 
virtual bool  IsPageMarginsSpecified (int pageNumber)
  Checks whether page margins have been specified for the given page number. More...
 
virtual FootnotesProperties  GetFootnotesProperties ()
  Gets iText.Layout.Properties.Margins.FootnotesProperties specified for the document to customize footnotes. More...
 
virtual void  SetFootnotesProperties (FootnotesProperties footnotesProperties)
  Sets iText.Layout.Properties.Margins.FootnotesProperties for the document. More...
 
virtual Rectangle  GetPageEffectiveArea (PageSize pageSize)
  Returns the area that will actually be used to write on the page, given the current margins. More...
 
override T1  GetDefaultProperty< T1 > (int property)
 
- Public Member Functions inherited from iText.Layout.RootElement< iText.Layout.Document >
  RootElement ()
  Creates a new RootElement instance. More...
 
virtual T  Add (IBlockElement element)
  Adds an element to the root. More...
 
virtual T  Add (Image image)
  Adds an image to the root. More...
 
virtual FontProvider  GetFontProvider ()
  Gets iText.Layout.Font.FontProvider if presents. More...
 
virtual void  SetFontProvider (FontProvider fontProvider)
  Sets iText.Layout.Font.FontProvider. More...
 
override bool  HasProperty (int property)
  Checks if this entity has the specified property. More...
 
override bool  HasOwnProperty (int property)
  Checks if this entity has the specified property, i.e. if it was set to this very element earlier More...
 
override T1  GetProperty< T1 > (int property)
  Gets the property from this entity. More...
 
override T1  GetOwnProperty< T1 > (int property)
  Gets own property from this entity. More...
 
override T1  GetDefaultProperty< T1 > (int property)
  Gets the default property from this entity. More...
 
override void  DeleteOwnProperty (int property)
  Deletes the own property of this entity. More...
 
override void  SetProperty (int property, Object value)
  Sets a property for this entity. More...
 
virtual RootRenderer  GetRenderer ()
  Gets the rootRenderer attribute, a specialized iText.Layout.Renderer.IRenderer that acts as the root object that other renderers descend from. More...
 
virtual T  ShowTextAligned (String text, float x, float y, TextAlignment? textAlign)
  Convenience method to write a text aligned about the specified point More...
 
virtual T  ShowTextAligned (String text, float x, float y, TextAlignment? textAlign, float angle)
  Convenience method to write a text aligned about the specified point More...
 
virtual T  ShowTextAligned (String text, float x, float y, TextAlignment? textAlign, VerticalAlignment? vertAlign, float angle)
  Convenience method to write a text aligned about the specified point More...
 
virtual T  ShowTextAligned (Paragraph p, float x, float y, TextAlignment? textAlign)
  Convenience method to write a text aligned about the specified point More...
 
virtual T  ShowTextAligned (Paragraph p, float x, float y, TextAlignment? textAlign, VerticalAlignment? vertAlign)
  Convenience method to write a text aligned about the specified point More...
 
virtual T  ShowTextAligned (Paragraph p, float x, float y, int pageNumber, TextAlignment? textAlign, VerticalAlignment? vertAlign, float radAngle)
  Convenience method to write a text aligned about the specified point More...
 
virtual T  ShowTextAlignedKerned (String text, float x, float y, TextAlignment? textAlign, VerticalAlignment? vertAlign, float radAngle)
  Convenience method to write a kerned text aligned about the specified point More...
 

Package Functions

override RootRenderer  EnsureRootRendererNotNull ()
 
virtual void  CheckClosingStatus ()
  Checks whether a method is invoked at the closed document More...
 
- Package Functions inherited from iText.Layout.RootElement< iText.Layout.Document >
virtual void  CreateAndAddRendererSubTree (IElement element)
 
void  EnsureRootTagIsCreated ()
  Ensures that the root tag is created in the tagging structure. More...
 

Additional Inherited Members

- Package Attributes inherited from iText.Layout.RootElement< iText.Layout.Document >
bool  immediateFlush
 
PdfDocument  pdfDocument
 
IList< IElement childElements
 
PdfFont  defaultFont
 
FontProvider  defaultFontProvider
 
ISplitCharacters  defaultSplitCharacters
 
RootRenderer  rootRenderer
 

Detailed Description

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

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 iText.Layout.Renderer.DocumentRenderer and setting an instance of this newly created with SetRenderer(iText.Layout.Renderer.DocumentRenderer).

Constructor & Destructor Documentation

◆ Document() [1/3]

iText.Layout.Document.Document ( PdfDocument  pdfDoc )
inline

Creates a document from a iText.Kernel.Pdf.PdfDocument.

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

Parameters
pdfDoc the in-memory representation of the PDF document

◆ Document() [2/3]

iText.Layout.Document.Document ( PdfDocument  pdfDoc,
PageSize  pageSize 
)
inline

Creates a document from a iText.Kernel.Pdf.PdfDocument with a manually set iText.Kernel.Geom.PageSize.

Parameters
pdfDoc the in-memory representation of the PDF document
pageSize the page size

◆ Document() [3/3]

iText.Layout.Document.Document ( PdfDocument  pdfDoc,
PageSize  pageSize,
bool  immediateFlush 
)
inline

Creates a document from a iText.Kernel.Pdf.PdfDocument with a manually set iText.Kernel.Geom.PageSize.

Parameters
pdfDoc the in-memory representation of the PDF document
pageSize the page size
immediateFlush if true, write pages and page-related instructions to the iText.Kernel.Pdf.PdfDocument as soon as possible.

Member Function Documentation

◆ Add() [1/2]

virtual iText.Layout.Document iText.Layout.Document.Add ( AreaBreak  areaBreak )
inlinevirtual

Terminates the current element, usually a page.

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

Parameters
areaBreak an iText.Layout.Element.AreaBreak , optionally with a specified size
Returns
this element

◆ Add() [2/2]

virtual iText.Layout.Document iText.Layout.Document.Add ( SectionBreak  sectionBreak )
inlinevirtual

Terminates the current page if it's not the first one in the document.

Terminates the current page if it's not the first one in the document. Sets the page size and/or page margins specified in the arguments for the next page.

Parameters
sectionBreak

iText.Layout.Element.SectionBreak , optionally with a specified page size and/or page margins

Returns
this same Document instance

◆ CheckClosingStatus()

virtual void iText.Layout.Document.CheckClosingStatus ( )
inlinepackagevirtual

Checks whether a method is invoked at the closed document

◆ Close()

override void iText.Layout.Document.Close ( )
inlinevirtual

Closes the document and associated PdfDocument.

Implements iText.Layout.RootElement< iText.Layout.Document >.

◆ Flush()

virtual void iText.Layout.Document.Flush ( )
inlinevirtual

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

◆ GetBottomMargin()

virtual float iText.Layout.Document.GetBottomMargin ( )
inlinevirtual

Gets the bottom margin, measured in points

Returns
a float containing the bottom margin value

◆ GetFootnotesProperties()

virtual FootnotesProperties iText.Layout.Document.GetFootnotesProperties ( )
inlinevirtual

Gets iText.Layout.Properties.Margins.FootnotesProperties specified for the document to customize footnotes.

Returns

iText.Layout.Properties.Margins.FootnotesProperties specified for the document

◆ GetLeftMargin()

virtual float iText.Layout.Document.GetLeftMargin ( )
inlinevirtual

Gets the left margin, measured in points

Returns
a float containing the left margin value

◆ GetPageEffectiveArea()

virtual Rectangle iText.Layout.Document.GetPageEffectiveArea ( PageSize  pageSize )
inlinevirtual

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

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.

Parameters
pageSize the size of the page to
Returns
a iText.Kernel.Geom.Rectangle with the required dimensions and origin point

◆ GetPageMargins()

virtual PageMarginBoxes iText.Layout.Document.GetPageMargins ( int  pageNumber )
inlinevirtual

Gets page margins by specified page number.

Parameters
pageNumber number of the page to get margins for
Returns

iText.Layout.Properties.Margins.PageMarginBoxes page margins

◆ GetPdfDocument()

virtual PdfDocument iText.Layout.Document.GetPdfDocument ( )
inlinevirtual

Gets PDF document.

Returns
the in-memory representation of the PDF document

◆ GetRightMargin()

virtual float iText.Layout.Document.GetRightMargin ( )
inlinevirtual

Gets the right margin, measured in points

Returns
a float containing the right margin value

◆ GetTopMargin()

virtual float iText.Layout.Document.GetTopMargin ( )
inlinevirtual

Gets the top margin, measured in points

Returns
a float containing the top margin value

◆ IsPageMarginsSpecified()

virtual bool iText.Layout.Document.IsPageMarginsSpecified ( int  pageNumber )
inlinevirtual

Checks whether page margins have been specified for the given page number.

Checks whether page margins have been specified for the given page number.

This method returns true if the margins for the page are determined by any of the following mechanisms (in order of precedence):

  1. Explicitly set margins for page number via SetPageMargins(int, iText.Layout.Properties.Margins.PageMarginBoxes)
  2. Matching rule set via SetPageMargins(System.Predicate, iText.Layout.Properties.Margins.PageMarginBoxes)
  3. Function set via SetPageMargins(System.Func)

NOTE: the method returns true even if the value produced by the mechanisms is null. Only when none of the above apply and the default static margins are used, this method returns false.

Parameters
pageNumber the page number to check
Returns

true if margins for the page are defined explicitly by page number, by matching rule or by function, false otherwise

◆ Relayout()

virtual void iText.Layout.Document.Relayout ( )
inlinevirtual

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

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 RootElement.immediateFlush to true.

◆ SetBottomMargin()

virtual void iText.Layout.Document.SetBottomMargin ( float  bottomMargin )
inlinevirtual

Sets the bottom margin, measured in points

Parameters
bottomMargin a float containing the new bottom margin value

◆ SetFootnotesProperties()

virtual void iText.Layout.Document.SetFootnotesProperties ( FootnotesProperties  footnotesProperties )
inlinevirtual

Sets iText.Layout.Properties.Margins.FootnotesProperties for the document.

Parameters
footnotesProperties

iText.Layout.Properties.Margins.FootnotesProperties to customize footnotes

◆ SetLeftMargin()

virtual void iText.Layout.Document.SetLeftMargin ( float  leftMargin )
inlinevirtual

Sets the left margin, measured in points

Parameters
leftMargin a float containing the new left margin value

◆ SetMargins()

virtual void iText.Layout.Document.SetMargins ( float  topMargin,
float  rightMargin,
float  bottomMargin,
float  leftMargin 
)
inlinevirtual

Convenience method to set all margins with one method.

Parameters
topMargin the upper margin
rightMargin the right margin
leftMargin the left margin
bottomMargin the lower margin

◆ SetPageMargins() [1/3]

virtual iText.Layout.Document iText.Layout.Document.SetPageMargins ( Func< int, PageMarginBoxes function )
inlinevirtual

Sets page margins for page based on provided function for page number.

Parameters
function function with page number as argument, return null in case result should be ignored and iText.Layout.Properties.Margins.PageMarginBoxes page margins return value
Returns
this same Document instance

◆ SetPageMargins() [2/3]

virtual iText.Layout.Document iText.Layout.Document.SetPageMargins ( int  pageNumber,
PageMarginBoxes  margins 
)
inlinevirtual

Sets page margins for page with provided number.

Parameters
pageNumber number of the page to set margins for
margins

iText.Layout.Properties.Margins.PageMarginBoxes page margins to set

Returns
this same Document instance

◆ SetPageMargins() [3/3]

virtual iText.Layout.Document iText.Layout.Document.SetPageMargins ( Predicate< int >  condition,
PageMarginBoxes  margins 
)
inlinevirtual

Sets page margins for page based on provided condition for page number.

Parameters
condition matching rule with page number as argument
margins

iText.Layout.Properties.Margins.PageMarginBoxes page margins to set

Returns
this same Document instance

◆ SetRenderer()

virtual void iText.Layout.Document.SetRenderer ( DocumentRenderer  documentRenderer )
inlinevirtual

Changes the iText.Layout.Renderer.DocumentRenderer at runtime.

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

Parameters
documentRenderer the DocumentRenderer to set

◆ SetRightMargin()

virtual void iText.Layout.Document.SetRightMargin ( float  rightMargin )
inlinevirtual

Sets the right margin, measured in points

Parameters
rightMargin a float containing the new right margin value

◆ SetTopMargin()

virtual void iText.Layout.Document.SetTopMargin ( float  topMargin )
inlinevirtual

Sets the top margin, measured in points

Parameters
topMargin a float containing the new top margin value