Package com.itextpdf.layout
Class Document
- All Implemented Interfaces:
-
IPropertyContainer,Closeable,AutoCloseable
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 DocumentRenderer and setting an instance of this newly created with setRenderer(com.itextpdf.layout.renderer.DocumentRenderer).
-
Field Summary
Fields inherited from class com.itextpdf.layout.RootElement
childElements, defaultFont, defaultFontProvider, defaultSplitCharacters, immediateFlush, pdfDocument, rootRendererFields inherited from class com.itextpdf.layout.ElementPropertyContainer
properties -
Constructor Summary
ConstructorsConstructorDescriptionDocument(PdfDocument pdfDoc) Creates a document from aPdfDocument.Document(PdfDocument pdfDoc, PageSize pageSize) Creates a document from aPdfDocumentwith a manually setPageSize.Document(PdfDocument pdfDoc, PageSize pageSize, boolean immediateFlush) Creates a document from aPdfDocumentwith a manually setPageSize. -
Method Summary
Modifier and TypeMethodDescriptionTerminates the current element, usually a page.add(IBlockElement element) Adds an element to the root.protected voidChecks whether a method is invoked at the closed documentvoidclose()Closes the document and associated PdfDocument.protected RootRenderervoidflush()Forces all registered renderers (including child element renderers) to flush their contents to the content stream.floatGets the bottom margin, measured in pointsT1 getDefaultProperty(int property) Gets the default property from this entity.floatGets the left margin, measured in pointsgetPageEffectiveArea(PageSize pageSize) Returns the area that will actually be used to write on the page, given the current margins.Gets PDF document.floatGets the right margin, measured in pointsfloatGets the top margin, measured in pointsvoidrelayout()Performs an entire recalculation of the document flow, taking into account all its current child elements.voidsetBottomMargin(float bottomMargin) Sets the bottom margin, measured in pointsvoidsetLeftMargin(float leftMargin) Sets the left margin, measured in pointsvoidsetMargins(float topMargin, float rightMargin, float bottomMargin, float leftMargin) Convenience method to set all margins with one method.voidsetRenderer(DocumentRenderer documentRenderer) Changes theDocumentRendererat runtime.voidsetRightMargin(float rightMargin) Sets the right margin, measured in pointsvoidsetTopMargin(float topMargin) Sets the top margin, measured in pointsMethods inherited from class com.itextpdf.layout.RootElement
add, createAndAddRendererSubTree, deleteOwnProperty, ensureRootTagIsCreated, getFontProvider, getOwnProperty, getProperty, getRenderer, hasOwnProperty, hasProperty, setFontProvider, setProperty, showTextAligned, showTextAligned, showTextAligned, showTextAligned, showTextAligned, showTextAligned, showTextAlignedKernedMethods inherited from class com.itextpdf.layout.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
-
Constructor Details
-
Document
Creates a document from aPdfDocument. Initializes the first page with thePdfDocument's current defaultPageSize.- Parameters:
-
pdfDoc- the in-memory representation of the PDF document
-
Document
Creates a document from aPdfDocumentwith a manually setPageSize.- Parameters:
-
pdfDoc- the in-memory representation of the PDF document -
pageSize- the page size
-
Document
Creates a document from aPdfDocumentwith a manually setPageSize.- Parameters:
-
pdfDoc- the in-memory representation of the PDF document -
pageSize- the page size -
immediateFlush- if true, write pages and page-related instructions to thePdfDocumentas soon as possible.
-
-
Method Details
-
close
public void close()Closes the document and associated PdfDocument. -
add
Terminates the current element, usually a page. Sets the next element to be the size specified in the argument.- Parameters:
-
areaBreak- anAreaBreak, optionally with a specified size - Returns:
- this element
-
add
Description copied from class:RootElementAdds an element to the root. The element is immediately placed in the contents.- Overrides:
-
addin classRootElement<Document> - Parameters:
-
element- an element with spacial margins, tabbing, and alignment - Returns:
- this element
- See Also:
-
getPdfDocument
Gets PDF document.- Returns:
- the in-memory representation of the PDF document
-
setRenderer
Changes theDocumentRendererat runtime. Use this to customize the Document'sIRendererbehavior.- Parameters:
-
documentRenderer- the DocumentRenderer to set
-
flush
public void flush()Forces all registered renderers (including child element renderers) to flush their contents to the content stream. -
relayout
public void relayout()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.immediateFlushtotrue. -
getLeftMargin
public float getLeftMargin()Gets the left margin, measured in points- Returns:
-
a
floatcontaining the left margin value
-
setLeftMargin
public void setLeftMargin(float leftMargin) Sets the left margin, measured in points- Parameters:
-
leftMargin- afloatcontaining the new left margin value
-
getRightMargin
public float getRightMargin()Gets the right margin, measured in points- Returns:
-
a
floatcontaining the right margin value
-
setRightMargin
public void setRightMargin(float rightMargin) Sets the right margin, measured in points- Parameters:
-
rightMargin- afloatcontaining the new right margin value
-
getTopMargin
public float getTopMargin()Gets the top margin, measured in points- Returns:
-
a
floatcontaining the top margin value
-
setTopMargin
public void setTopMargin(float topMargin) Sets the top margin, measured in points- Parameters:
-
topMargin- afloatcontaining the new top margin value
-
getBottomMargin
public float getBottomMargin()Gets the bottom margin, measured in points- Returns:
-
a
floatcontaining the bottom margin value
-
setBottomMargin
public void setBottomMargin(float bottomMargin) Sets the bottom margin, measured in points- Parameters:
-
bottomMargin- afloatcontaining the new bottom margin value
-
setMargins
public void setMargins(float topMargin, float rightMargin, float bottomMargin, float leftMargin) 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
-
getPageEffectiveArea
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
Rectanglewith the required dimensions and origin point
-
getDefaultProperty
publicT1 getDefaultProperty (int property) Description copied from interface:IPropertyContainerGets the default property from this entity.- Specified by:
-
getDefaultPropertyin interfaceIPropertyContainer - Overrides:
-
getDefaultPropertyin classRootElement<Document> - Type Parameters:
-
T1- the return type associated with the property - Parameters:
-
property- the property to be retrieved - Returns:
-
the default property value. If the default property is not defined,
nullwill be returned
-
ensureRootRendererNotNull
- Specified by:
-
ensureRootRendererNotNullin classRootElement<Document>
-
checkClosingStatus
protected void checkClosingStatus()Checks whether a method is invoked at the closed document
-