Class Canvas
This class is used for adding content directly onto a specified PdfCanvas.
public class Canvas : RootElement<Canvas>, IPropertyContainer, IDisposable
- Inheritance
-
Canvas
- Implements
- Inherited Members
Remarks
This class is used for adding content directly onto a specified 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.
Constructors
Canvas(PdfCanvas, Rectangle)
Creates a new Canvas to manipulate a specific content stream, which might be for example a page or PdfFormXObject stream.
public Canvas(PdfCanvas pdfCanvas, Rectangle rootArea)
Parameters
pdfCanvas
PdfCanvasthe low-level content stream writer
rootArea
Rectanglethe maximum area that the Canvas may write upon
Canvas(PdfCanvas, Rectangle, bool)
Creates a new Canvas to manipulate a specific document and page.
public Canvas(PdfCanvas pdfCanvas, Rectangle rootArea, bool immediateFlush)
Parameters
pdfCanvas
PdfCanvasThe low-level content stream writer
rootArea
RectangleThe maximum area that the Canvas may write upon
immediateFlush
boolWhether to flush the canvas immediately after operations, false otherwise
Canvas(PdfPage, Rectangle)
Creates a new Canvas to manipulate a specific page content stream.
public Canvas(PdfPage page, Rectangle rootArea)
Parameters
page
PdfPagethe page on which this canvas will be rendered, shall not be flushed (see IsFlushed() ).
rootArea
Rectanglethe maximum area that the Canvas may write upon
Remarks
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 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 IsTagged() is true, using this constructor would automatically enable the tagging for the content. Regarding tagging the effect is the same as using EnableAutoTagging(PdfPage).Canvas(PdfFormXObject, PdfDocument)
Creates a new Canvas to manipulate a specific PdfFormXObject.
public Canvas(PdfFormXObject formXObject, PdfDocument pdfDocument)
Parameters
formXObject
PdfFormXObjectthe form
pdfDocument
PdfDocumentthe document that the resulting content stream will be written to
Fields
page
Is initialized and used only when Canvas element autotagging is enabled, see EnableAutoTagging(PdfPage).
protected PdfPage page
Field Value
Remarks
Is initialized and used only when Canvas element autotagging is enabled, see EnableAutoTagging(PdfPage). It is also used to determine if autotagging is enabled.
pdfCanvas
protected PdfCanvas pdfCanvas
Field Value
rootArea
protected Rectangle rootArea
Field Value
Methods
Close()
Closes the Canvas.
public override void Close()
Remarks
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.
EnableAutoTagging(PdfPage)
Enables canvas content autotagging.
public virtual void EnableAutoTagging(PdfPage page)
Parameters
page
PdfPagethe page, on which this canvas will be rendered.
Remarks
Enables canvas content autotagging. By default it is disabled.
EnsureRootRendererNotNull()
protected override RootRenderer EnsureRootRendererNotNull()
Returns
Flush()
Forces all registered renderers (including child element renderers) to flush their contents to the content stream.
public virtual void Flush()
GetPage()
The page on which this canvas will be rendered.
public virtual PdfPage GetPage()
Returns
GetPdfCanvas()
Gets the PdfCanvas.
public virtual PdfCanvas GetPdfCanvas()
Returns
- PdfCanvas
the low-level content stream writer
GetPdfDocument()
Gets the PdfDocument for this canvas.
public virtual PdfDocument GetPdfDocument()
Returns
- PdfDocument
the document that the resulting content stream will be written to
GetRootArea()
Gets the root area rectangle.
public virtual Rectangle GetRootArea()
Returns
- Rectangle
the maximum area that the Canvas may write upon
IsAutoTaggingEnabled()
public virtual bool IsAutoTaggingEnabled()
Returns
- bool
true if autotagging of canvas content is enabled. Default value - false.
IsCanvasOfPage()
Defines if the canvas is exactly the direct content of the page.
public virtual bool IsCanvasOfPage()
Returns
- bool
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(PdfPage, Rectangle) constructor overload.
Remarks
Defines if the canvas is exactly the direct content of the page. This is known definitely only if this instance was created by Canvas(PdfPage, Rectangle) constructor overload, otherwise this method returns false.
Relayout()
Performs an entire recalculation of the element flow on the canvas, taking into account all its current child elements.
public virtual void Relayout()
Remarks
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
immediateFlush
to true
.
SetRenderer(CanvasRenderer)
Sets the IRenderer for this Canvas.
public virtual void SetRenderer(CanvasRenderer canvasRenderer)
Parameters
canvasRenderer
CanvasRenderera renderer specific for canvas operations