iText 7 7.1.9 API
iText.Layout.Canvas Class Reference

This class is used for adding content directly onto a specified iText.Kernel.Pdf.Canvas.PdfCanvas. More...

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

Public Member Functions

  Canvas (PdfPage page, Rectangle rootArea)
  Creates a new Canvas to manipulate a specific page content stream. More...
 
  Canvas (PdfCanvas pdfCanvas, PdfDocument pdfDocument, Rectangle rootArea)
  Creates a new Canvas to manipulate a specific document and content stream, which might be for example a page or iText.Kernel.Pdf.Xobject.PdfFormXObject stream. More...
 
  Canvas (PdfCanvas pdfCanvas, PdfDocument pdfDocument, Rectangle rootArea, bool immediateFlush)
  Creates a new Canvas to manipulate a specific document and page. More...
 
  Canvas (PdfFormXObject formXObject, PdfDocument pdfDocument)
  Creates a new Canvas to manipulate a specific iText.Kernel.Pdf.Xobject.PdfFormXObject. More...
 
virtual PdfDocument  GetPdfDocument ()
  Gets the iText.Kernel.Pdf.PdfDocument for this canvas. More...
 
virtual Rectangle  GetRootArea ()
  Gets the root area rectangle. More...
 
virtual PdfCanvas  GetPdfCanvas ()
  Gets the iText.Kernel.Pdf.Canvas.PdfCanvas. More...
 
virtual void  SetRenderer (CanvasRenderer canvasRenderer)
  Sets the iText.Layout.Renderer.IRenderer for this Canvas. More...
 
virtual PdfPage  GetPage ()
  The page on which this canvas will be rendered. More...
 
virtual void  EnableAutoTagging (PdfPage page)
  Enables canvas content autotagging. More...
 
virtual bool  IsAutoTaggingEnabled ()
 
Returns
true if autotagging of canvas content is enabled. Default value - false.

 
virtual bool  IsCanvasOfPage ()
  Defines if the canvas is exactly the direct content of the page. More...
 
virtual void  Relayout ()
  Performs an entire recalculation of the element flow on the canvas, taking into account all its current child elements. More...
 
virtual void  Flush ()
  Forces all registered renderers (including child element renderers) to flush their contents to the content stream. More...
 
override void  Close ()
  Closes the Canvas. More...
 
- Public Member Functions inherited from iText.Layout.RootElement< iText.Layout.Canvas >
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...
 

Detailed Description

This class is used for adding content directly onto a specified iText.Kernel.Pdf.Canvas.PdfCanvas.

This class is used for adding content directly onto a specified iText.Kernel.Pdf.Canvas.PdfCanvas. Canvas does not know the concept of a page, so it can't reflow to a 'next' Canvas. This class effectively acts as a bridge between the high-level layout API and the low-level kernel API.

Constructor & Destructor Documentation

◆ Canvas() [1/4]

iText.Layout.Canvas.Canvas ( PdfPage  page,
Rectangle  rootArea 
)
inline

Creates a new Canvas to manipulate a specific page content stream.

Creates a new Canvas to manipulate a specific page content stream. The given page shall not be flushed: drawing on flushed pages is impossible because their content is already written to the output stream. Use this constructor to be able to add iText.Layout.Element.Link elements on it (using any other constructor would result in inability to add PDF annotations, based on which, for example, links work).

If the iText.Kernel.Pdf.PdfDocument.IsTagged() is true, using this constructor would automatically enable the tagging for the content. Regarding tagging the effect is the same as using EnableAutoTagging(iText.Kernel.Pdf.PdfPage).

Parameters
page the page on which this canvas will be rendered, shall not be flushed (see iText.Kernel.Pdf.PdfObjectWrapper<T>.IsFlushed() ).
rootArea the maximum area that the Canvas may write upon

◆ Canvas() [2/4]

iText.Layout.Canvas.Canvas ( PdfCanvas  pdfCanvas,
PdfDocument  pdfDocument,
Rectangle  rootArea 
)
inline

Creates a new Canvas to manipulate a specific document and content stream, which might be for example a page or iText.Kernel.Pdf.Xobject.PdfFormXObject stream.

Parameters
pdfCanvas the low-level content stream writer
pdfDocument the document that the resulting content stream will be written to
rootArea the maximum area that the Canvas may write upon

◆ Canvas() [3/4]

iText.Layout.Canvas.Canvas ( PdfCanvas  pdfCanvas,
PdfDocument  pdfDocument,
Rectangle  rootArea,
bool  immediateFlush 
)
inline

Creates a new Canvas to manipulate a specific document and page.

Parameters
pdfCanvas The low-level content stream writer
pdfDocument The document that the resulting content stream will be written to
rootArea The maximum area that the Canvas may write upon
immediateFlush Whether to flush the canvas immediately after operations, false otherwise

◆ Canvas() [4/4]

iText.Layout.Canvas.Canvas ( PdfFormXObject  formXObject,
PdfDocument  pdfDocument 
)
inline

Creates a new Canvas to manipulate a specific iText.Kernel.Pdf.Xobject.PdfFormXObject.

Parameters
formXObject the form
pdfDocument the document that the resulting content stream will be written to

Member Function Documentation

◆ Close()

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

Closes the Canvas.

Closes the Canvas . Although not completely necessary in all cases, it is still recommended to call this method when you are done working with Canvas object, as due to some properties set there might be some 'hanging' elements, which are waiting other elements to be added and processed. Close() tells the Canvas that no more elements will be added and it is time to finish processing all the elements.

Implements iText.Layout.RootElement< iText.Layout.Canvas >.

◆ EnableAutoTagging()

virtual void iText.Layout.Canvas.EnableAutoTagging ( PdfPage  page )
inlinevirtual

Enables canvas content autotagging.

Enables canvas content autotagging. By default it is disabled.

Parameters
page the page, on which this canvas will be rendered.

◆ Flush()

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

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

◆ GetPage()

virtual PdfPage iText.Layout.Canvas.GetPage ( )
inlinevirtual

The page on which this canvas will be rendered.

Returns
the specified iText.Kernel.Pdf.PdfPage instance, might be null if this the page was not set.

◆ GetPdfCanvas()

virtual PdfCanvas iText.Layout.Canvas.GetPdfCanvas ( )
inlinevirtual

Gets the iText.Kernel.Pdf.Canvas.PdfCanvas.

Returns
the low-level content stream writer

◆ GetPdfDocument()

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

Gets the iText.Kernel.Pdf.PdfDocument for this canvas.

Returns
the document that the resulting content stream will be written to

◆ GetRootArea()

virtual Rectangle iText.Layout.Canvas.GetRootArea ( )
inlinevirtual

Gets the root area rectangle.

Returns
the maximum area that the Canvas may write upon

◆ IsCanvasOfPage()

virtual bool iText.Layout.Canvas.IsCanvasOfPage ( )
inlinevirtual

Defines if the canvas is exactly the direct content of the page.

Defines if the canvas is exactly the direct content of the page. This is known definitely only if this instance was created by Canvas(iText.Kernel.Pdf.PdfPage, iText.Kernel.Geom.Rectangle) constructor overload, otherwise this method returns false.

Returns
true if the canvas on which this instance performs drawing is directly the canvas of the page; false if the instance of this class was created not with Canvas(iText.Kernel.Pdf.PdfPage, iText.Kernel.Geom.Rectangle) constructor overload.

◆ Relayout()

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

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

Performs an entire recalculation of the element flow on the canvas, taking into account all its current child elements. May become very resource-intensive for large documents. Do not use when you have set RootElement<T>.immediateFlush to true.

◆ SetRenderer()

virtual void iText.Layout.Canvas.SetRenderer ( CanvasRenderer  canvasRenderer )
inlinevirtual

Sets the iText.Layout.Renderer.IRenderer for this Canvas.

Parameters
canvasRenderer a renderer specific for canvas operations