Class Canvas
- All Implemented Interfaces:
IPropertyContainer, Closeable, AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprotected PdfPageIs initialized and used only when Canvas element autotagging is enabled, seeenableAutoTagging(PdfPage).protected PdfCanvasprotected RectangleFields inherited from class RootElement
childElements, defaultFont, defaultFontProvider, defaultSplitCharacters, immediateFlush, pdfDocument, rootRendererFields inherited from class ElementPropertyContainer
properties -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Canvas to manipulate a specific content stream, which might be for example a page orPdfFormXObjectstream.Creates a new Canvas to manipulate a specific document and page.Creates a new Canvas to manipulate a specific page content stream.Canvas(PdfFormXObject formXObject, PdfDocument pdfDocument) Creates a new Canvas to manipulate a specificPdfFormXObject. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes theCanvas.voidenableAutoTagging(PdfPage page) Enables canvas content autotagging.protected RootRenderervoidflush()Forces all registered renderers (including child element renderers) to flush their contents to the content stream.getPage()The page on which this canvas will be rendered.Gets thePdfCanvas.Gets thePdfDocumentfor this canvas.Gets the root area rectangle.private static PdfCanvasbooleanbooleanDefines if the canvas is exactly the direct content of the page.voidrelayout()Performs an entire recalculation of the element flow on the canvas, taking into account all its current child elements.voidsetRenderer(CanvasRenderer canvasRenderer) Sets theIRendererfor this Canvas.Methods inherited from class RootElement
add, add, createAndAddRendererSubTree, deleteOwnProperty, ensureRootTagIsCreated, getDefaultProperty, getFontProvider, getOwnProperty, getProperty, getRenderer, hasOwnProperty, hasProperty, setFontProvider, setProperty, showTextAligned, showTextAligned, showTextAligned, showTextAligned, showTextAligned, showTextAligned, showTextAlignedKernedMethods inherited from class ElementPropertyContainer
getSplitCharacters, getStrokeColor, getStrokeWidth, getTextRenderingMode, getTransparentStrokeColor, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundImage, setBackgroundImage, setBaseDirection, setBorder, setBorderBottom, setBorderBottomLeftRadius, setBorderBottomRightRadius, setBorderLeft, setBorderRadius, setBorderRight, setBorderTop, setBorderTopLeftRadius, setBorderTopRightRadius, setCharacterSpacing, setDashPattern, setDestination, setFixedPosition, setFixedPosition, setFixedPosition, setFixedPosition, setFont, setFontColor, setFontColor, setFontColor, setFontFamily, setFontFamily, setFontKerning, setFontScript, setFontSize, setHorizontalAlignment, setHyphenation, setLineThrough, setOpacity, setRelativePosition, setSplitCharacters, setStrokeColor, setStrokeColor, setStrokeColor, setStrokeWidth, setTextAlignment, setTextRenderingMode, setUnderline, setUnderline, setUnderline, setUnderline, setUnderline, setWordSpacing, simulateBold, simulateItalic
-
Field Details
-
pdfCanvas
-
rootArea
-
page
Is initialized and used only when Canvas element autotagging is enabled, seeenableAutoTagging(PdfPage). It is also used to determine if autotagging is enabled. -
isCanvasOfPage
private boolean isCanvasOfPage
-
-
Constructor Details
-
Canvas
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 addLinkelements on it (using any other constructor would result in inability to add PDF annotations, based on which, for example, links work).If the
PdfDocument.isTagged()is true, using this constructor would automatically enable the tagging for the content. Regarding tagging the effect is the same as usingenableAutoTagging(PdfPage).- Parameters:
page- the page on which this canvas will be rendered, shall not be flushed (seePdfObjectWrapper.isFlushed()).rootArea- the maximum area that the Canvas may write upon
-
Canvas
Creates a new Canvas to manipulate a specific content stream, which might be for example a page orPdfFormXObjectstream.- Parameters:
pdfCanvas- the low-level content stream writerrootArea- the maximum area that the Canvas may write upon
-
Canvas
Creates a new Canvas to manipulate a specific document and page.- Parameters:
pdfCanvas- The low-level content stream writerrootArea- The maximum area that the Canvas may write uponimmediateFlush- Whether to flush the canvas immediately after operations, false otherwise
-
Canvas
Creates a new Canvas to manipulate a specificPdfFormXObject.- Parameters:
formXObject- the formpdfDocument- the document that the resulting content stream will be written to
-
-
Method Details
-
getPdfDocument
Gets thePdfDocumentfor this canvas.- Returns:
- the document that the resulting content stream will be written to
-
getRootArea
Gets the root area rectangle.- Returns:
- the maximum area that the Canvas may write upon
-
getPdfCanvas
-
setRenderer
Sets theIRendererfor this Canvas.- Parameters:
canvasRenderer- a renderer specific for canvas operations
-
getPage
-
enableAutoTagging
Enables canvas content autotagging. By default it is disabled.- Parameters:
page- the page, on which this canvas will be rendered.
-
isAutoTaggingEnabled
public boolean isAutoTaggingEnabled()- Returns:
- true if autotagging of canvas content is enabled. Default value - false.
-
isCanvasOfPage
public boolean isCanvasOfPage()Defines if the canvas is exactly the direct content of the page. This is known definitely only if this instance was created byCanvas(PdfPage, 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(PdfPage, Rectangle)constructor overload.
-
relayout
public void relayout()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 setRootElement.immediateFlushtotrue. -
flush
public void flush()Forces all registered renderers (including child element renderers) to flush their contents to the content stream. -
close
public void close()Closes theCanvas. Although not completely necessary in all cases, it is still recommended to call this method when you are done working withCanvasobject, as due to some properties set there might be some 'hanging' elements, which are waiting other elements to be added and processed.close()tells theCanvasthat no more elements will be added and it is time to finish processing all the elements. -
ensureRootRendererNotNull
- Specified by:
ensureRootRendererNotNullin classRootElement<Canvas>
-
initPdfCanvasOrThrowIfPageIsFlushed
-