- java.lang.Object
-
- com.itextpdf.text.Document
-
- com.itextpdf.text.pdf.PdfDocument
-
- All Implemented Interfaces:
DocListener,ElementListener,java.util.EventListener
public class PdfDocument extends Document
PdfDocumentis the class that is used byPdfWriterto translate aDocumentinto a PDF with different pages.A
PdfDocumentalways listens to aDocumentand adds the Pdf representation of everyElementthat is added to theDocument.- Since:
- 2.0.8 (class was package-private before)
- See Also:
Document,DocListener,PdfWriter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPdfDocument.Indentationstatic classPdfDocument.PdfInfoPdfInfois the PDF InfoDictionary.protected static classPdfDocument.RenderingContextThis is a helper class for adding a Table to a document.
-
Field Summary
Fields Modifier and Type Field Description protected PdfDictionaryadditionalActionsprotected intalignmentThis represents the current alignment of the PDF Elements.protected PdfActionanchorActionThe current activePdfActionwhen processing anAnchor.protected java.util.HashMapboxSizeThis is the size of the several boxes that will be used in the next page.protected PdfCollectioncollectionprotected floatcurrentHeightThis is the current height of the document.protected PdfOutlinecurrentOutlineThis is the currentPdfOutlinein the hierarchy of outlines.protected java.util.HashMapdocumentFileAttachmentprotected java.util.HashMapdocumentLevelJSprotected intdurationThe duration of the pageprotected booleanfirstPageEventSignals that OnOpenDocument should be called.protected PdfContentBytegraphicsThis is the PdfContentByte object, containing the borders and other Graphics.protected floatimageEndThis is the position where the image ends.protected ImageimageWaitThis is the image that could not be shown on a previous page.protected PdfDocument.Indentationindentationprotected PdfDocument.PdfInfoinfosome meta information about the Document.protected booleanisSectionTitleSignals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).protected intlastElementTypeHolds the type of the last element, that has been added to the document.protected floatleadingThis represents the leading of the lines.protected intleadingCountSignals that the current leading has to be subtracted from a YMark object when positive.protected PdfLinelineThe line that is currently being written.protected java.util.ArrayListlinesThe lines that are written until now.protected java.util.TreeMaplocalDestinationsStores the destinations keyed by name.protected intmarkPointprotected floatnextMarginBottommargin in y direction starting from the bottom.protected floatnextMarginLeftmargin in x direction starting from the left.protected floatnextMarginRightmargin in x direction starting from the right.protected floatnextMarginTopmargin in y direction starting from the top.protected RectanglenextPageSizeThis is the size of the next page.protected PdfActionopenActionActionprotected java.lang.StringopenActionNameprotected PdfDictionarypageAAprotected PdfPageLabelspageLabelsprotected com.itextpdf.text.pdf.PageResourcespageResourcesThis are the page resources of the current Page.protected PdfOutlinerootOutlineThis is the root outline of the document.protected static java.text.DecimalFormatSIXTEEN_DIGITSprotected booleanstrictImageSequenceHolds value of property strictImageSequence.protected PdfContentBytetextThis is the PdfContentByte object, containing the text.protected inttextEmptySizeprotected java.util.HashMapthisBoxSizeThis is the size of the several boxes of the current Page.protected PdfIndirectReferencethumbprotected PdfTransitiontransitionThe page transitionprotected PdfViewerPreferencesImpviewerPreferencesContains the Viewer preferences of this PDF document.protected PdfWriterwriterThePdfWriter.protected byte[]xmpMetadataXMP Metadata for the page.-
Fields inherited from class com.itextpdf.text.Document
chapternumber, close, compress, footer, header, htmlStyleClass, javaScript_onLoad, javaScript_onUnLoad, marginBottom, marginLeft, marginMirroring, marginMirroringTopBottom, marginRight, marginTop, open, pageN, pageSize, plainRandomAccess, wmfFontCorrection
-
-
Constructor Summary
Constructors Constructor Description PdfDocument()Constructs a new PDF document.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Element element)Signals that anElementwas added to theDocument.protected voidadd(Image image)Adds an image to the document.protected voidaddSpacing(float extraspace, float oldleading, Font f)Adds extra space.voidaddWriter(PdfWriter writer)Adds aPdfWriterto thePdfDocument.protected voidanalyzeRow(java.util.ArrayList rows, PdfDocument.RenderingContext ctx)protected voidcarriageReturn()If the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.voidclearTextWrap()Method added by Pelikan Stephanvoidclose()Closes the document.protected voidconsumeRowspan(java.util.ArrayList row, PdfDocument.RenderingContext ctx)protected voiddoFooter()protected voiddoHeader()protected voidensureNewLine()Ensures that a new line has been started.protected java.util.ArrayListextractRows(java.util.ArrayList cells, PdfDocument.RenderingContext ctx)protected floatflushLines()Writes all the lines to the text-object.floatgetLeading()Getter for the current leading.PdfOutlinegetRootOutline()Gets the root outline.floatgetVerticalPosition(boolean ensureNewLine)Gets the current vertical page position.protected floatindentLeft()Gets the indentation on the left side.protected floatindentRight()Gets the indentation on the right side.protected floatindentTop()Gets the indentation on the top side.protected voidinitPage()Initializes a page.protected booleanmayBeRemoved(java.util.ArrayList row)protected voidnewLine()Adds the current line to the list of lines and also adds an empty line.booleannewPage()Makes a new page and sends it to thePdfWriter.voidopen()Opens the document.protected voidrenderCells(PdfDocument.RenderingContext ctx, java.util.List cells, boolean hasToFit)voidresetFooter()Resets the footer of this document.voidresetHeader()Resets the header of this document.voidresetPageCount()Sets the page number to 0.voidsetCollection(PdfCollection collection)Sets the collection dictionary.voidsetFooter(HeaderFooter footer)Changes the footer of this document.voidsetHeader(HeaderFooter header)Changes the header of this document.booleansetMarginMirroring(boolean MarginMirroring)Set the margin mirroring.booleansetMarginMirroringTopBottom(boolean MarginMirroringTopBottom)Set the margin mirroring.booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)Sets the margins.protected voidsetNewPageSizeAndMargins()voidsetPageCount(int pageN)Sets the page number.booleansetPageSize(Rectangle pageSize)Sets the pagesize.voidsetXmpMetadata(byte[] xmpMetadata)Use this method to set the XMP Metadata.-
Methods inherited from class com.itextpdf.text.Document
addAuthor, addCreationDate, addCreator, addDocListener, addHeader, addKeywords, addProducer, addSubject, addTitle, bottom, bottom, bottomMargin, getHtmlStyleClass, getJavaScript_onLoad, getJavaScript_onUnLoad, getPageNumber, getPageSize, getProduct, getRelease, getVersion, isMarginMirroring, isOpen, left, left, leftMargin, removeDocListener, right, right, rightMargin, setHtmlStyleClass, setJavaScript_onLoad, setJavaScript_onUnLoad, top, top, topMargin
-
-
-
-
Field Detail
-
writer
protected PdfWriter writer
ThePdfWriter.
-
text
protected PdfContentByte text
This is the PdfContentByte object, containing the text.
-
graphics
protected PdfContentByte graphics
This is the PdfContentByte object, containing the borders and other Graphics.
-
leading
protected float leading
This represents the leading of the lines.
-
alignment
protected int alignment
This represents the current alignment of the PDF Elements.
-
currentHeight
protected float currentHeight
This is the current height of the document.
-
isSectionTitle
protected boolean isSectionTitle
Signals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).- Since:
- 2.1.2
-
leadingCount
protected int leadingCount
Signals that the current leading has to be subtracted from a YMark object when positive.- Since:
- 2.1.2
-
anchorAction
protected PdfAction anchorAction
The current activePdfActionwhen processing anAnchor.
-
textEmptySize
protected int textEmptySize
-
xmpMetadata
protected byte[] xmpMetadata
XMP Metadata for the page.
-
nextMarginLeft
protected float nextMarginLeft
margin in x direction starting from the left. Will be valid in the next page
-
nextMarginRight
protected float nextMarginRight
margin in x direction starting from the right. Will be valid in the next page
-
nextMarginTop
protected float nextMarginTop
margin in y direction starting from the top. Will be valid in the next page
-
nextMarginBottom
protected float nextMarginBottom
margin in y direction starting from the bottom. Will be valid in the next page
-
firstPageEvent
protected boolean firstPageEvent
Signals that OnOpenDocument should be called.
-
line
protected PdfLine line
The line that is currently being written.
-
lines
protected java.util.ArrayList lines
The lines that are written until now.
-
lastElementType
protected int lastElementType
Holds the type of the last element, that has been added to the document.
-
indentation
protected PdfDocument.Indentation indentation
-
info
protected PdfDocument.PdfInfo info
some meta information about the Document.
-
rootOutline
protected PdfOutline rootOutline
This is the root outline of the document.
-
currentOutline
protected PdfOutline currentOutline
This is the currentPdfOutlinein the hierarchy of outlines.
-
viewerPreferences
protected PdfViewerPreferencesImp viewerPreferences
Contains the Viewer preferences of this PDF document.
-
pageLabels
protected PdfPageLabels pageLabels
-
localDestinations
protected java.util.TreeMap localDestinations
Stores the destinations keyed by name. Value isObject[]{PdfAction,PdfIndirectReference,PdfDestintion}.
-
documentLevelJS
protected java.util.HashMap documentLevelJS
-
SIXTEEN_DIGITS
protected static final java.text.DecimalFormat SIXTEEN_DIGITS
-
documentFileAttachment
protected java.util.HashMap documentFileAttachment
-
openActionName
protected java.lang.String openActionName
-
openActionAction
protected PdfAction openActionAction
-
additionalActions
protected PdfDictionary additionalActions
-
collection
protected PdfCollection collection
-
markPoint
protected int markPoint
-
nextPageSize
protected Rectangle nextPageSize
This is the size of the next page.
-
thisBoxSize
protected java.util.HashMap thisBoxSize
This is the size of the several boxes of the current Page.
-
boxSize
protected java.util.HashMap boxSize
This is the size of the several boxes that will be used in the next page.
-
duration
protected int duration
The duration of the page
-
transition
protected PdfTransition transition
The page transition
-
pageAA
protected PdfDictionary pageAA
-
thumb
protected PdfIndirectReference thumb
-
pageResources
protected com.itextpdf.text.pdf.PageResources pageResources
This are the page resources of the current Page.
-
strictImageSequence
protected boolean strictImageSequence
Holds value of property strictImageSequence.
-
imageEnd
protected float imageEnd
This is the position where the image ends.
-
imageWait
protected Image imageWait
This is the image that could not be shown on a previous page.
-
-
Method Detail
-
addWriter
public void addWriter(PdfWriter writer) throws DocumentException
Adds aPdfWriterto thePdfDocument.- Parameters:
writer- thePdfWriterthat writes everything what is added to this document to an outputstream.- Throws:
DocumentException- on error
-
getLeading
public float getLeading()
Getter for the current leading.- Returns:
- the current leading
- Since:
- 2.1.2
-
add
public boolean add(Element element) throws DocumentException
Signals that anElementwas added to theDocument.- Specified by:
addin interfaceElementListener- Overrides:
addin classDocument- Parameters:
element- the element to add- Returns:
trueif the element was added,falseif not.- Throws:
DocumentException- when a document isn't open yet, or has been closed
-
open
public void open()
Opens the document.You have to open the document before you can begin to add content to the body of the document.
- Specified by:
openin interfaceDocListener- Overrides:
openin classDocument
-
close
public void close()
Closes the document. Once all the content has been written in the body, you have to close the body. After that nothing can be written to the body anymore.- Specified by:
closein interfaceDocListener- Overrides:
closein classDocument
-
setXmpMetadata
public void setXmpMetadata(byte[] xmpMetadata)
Use this method to set the XMP Metadata.- Parameters:
xmpMetadata- The xmpMetadata to set.
-
newPage
public boolean newPage()
Makes a new page and sends it to thePdfWriter.- Specified by:
newPagein interfaceDocListener- Overrides:
newPagein classDocument- Returns:
- a
boolean
-
setPageSize
public boolean setPageSize(Rectangle pageSize)
Sets the pagesize.- Specified by:
setPageSizein interfaceDocListener- Overrides:
setPageSizein classDocument- Parameters:
pageSize- the new pagesize- Returns:
trueif the page size was set
-
setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)Sets the margins.- Specified by:
setMarginsin interfaceDocListener- Overrides:
setMarginsin classDocument- Parameters:
marginLeft- the margin on the leftmarginRight- the margin on the rightmarginTop- the margin on the topmarginBottom- the margin on the bottom- Returns:
- a
boolean
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring)
Description copied from class:DocumentSet the margin mirroring. It will mirror right/left margins for odd/even pages.Note: it will not work with
Table.- Specified by:
setMarginMirroringin interfaceDocListener- Overrides:
setMarginMirroringin classDocument- Parameters:
MarginMirroring-trueto mirror the margins- Returns:
- always
true - See Also:
DocListener.setMarginMirroring(boolean)
-
setMarginMirroringTopBottom
public boolean setMarginMirroringTopBottom(boolean MarginMirroringTopBottom)
Description copied from class:DocumentSet the margin mirroring. It will mirror top/bottom margins for odd/even pages.Note: it will not work with
Table.- Specified by:
setMarginMirroringTopBottomin interfaceDocListener- Overrides:
setMarginMirroringTopBottomin classDocument- Parameters:
MarginMirroringTopBottom-trueto mirror the margins- Returns:
- always
true - Since:
- 2.1.6
- See Also:
DocListener.setMarginMirroring(boolean)
-
setPageCount
public void setPageCount(int pageN)
Sets the page number.- Specified by:
setPageCountin interfaceDocListener- Overrides:
setPageCountin classDocument- Parameters:
pageN- the new page number
-
resetPageCount
public void resetPageCount()
Sets the page number to 0.- Specified by:
resetPageCountin interfaceDocListener- Overrides:
resetPageCountin classDocument
-
setHeader
public void setHeader(HeaderFooter header)
Changes the header of this document.- Specified by:
setHeaderin interfaceDocListener- Overrides:
setHeaderin classDocument- Parameters:
header- the new header
-
resetHeader
public void resetHeader()
Resets the header of this document.- Specified by:
resetHeaderin interfaceDocListener- Overrides:
resetHeaderin classDocument
-
setFooter
public void setFooter(HeaderFooter footer)
Changes the footer of this document.- Specified by:
setFooterin interfaceDocListener- Overrides:
setFooterin classDocument- Parameters:
footer- the new footer
-
resetFooter
public void resetFooter()
Resets the footer of this document.- Specified by:
resetFooterin interfaceDocListener- Overrides:
resetFooterin classDocument
-
initPage
protected void initPage() throws DocumentExceptionInitializes a page.If the footer/header is set, it is printed.
- Throws:
DocumentException- on error
-
newLine
protected void newLine() throws DocumentExceptionAdds the current line to the list of lines and also adds an empty line.- Throws:
DocumentException- on error
-
carriageReturn
protected void carriageReturn()
If the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.
-
getVerticalPosition
public float getVerticalPosition(boolean ensureNewLine)
Gets the current vertical page position.- Parameters:
ensureNewLine- Tells whether a new line shall be enforced. This may cause side effects for elements that do not terminate the lines they've started because those lines will get terminated.- Returns:
- The current vertical page position.
-
ensureNewLine
protected void ensureNewLine()
Ensures that a new line has been started.
-
flushLines
protected float flushLines() throws DocumentExceptionWrites all the lines to the text-object.- Returns:
- the displacement that was caused
- Throws:
DocumentException- on error
-
indentLeft
protected float indentLeft()
Gets the indentation on the left side.- Returns:
- a margin
-
indentRight
protected float indentRight()
Gets the indentation on the right side.- Returns:
- a margin
-
indentTop
protected float indentTop()
Gets the indentation on the top side.- Returns:
- a margin
-
addSpacing
protected void addSpacing(float extraspace, float oldleading, Font f)Adds extra space. This method should probably be rewritten.
-
getRootOutline
public PdfOutline getRootOutline()
Gets the root outline. All the outlines must be created with a parent. The first level is created with this outline.- Returns:
- the root outline
-
setCollection
public void setCollection(PdfCollection collection)
Sets the collection dictionary.- Parameters:
collection- a dictionary of type PdfCollection
-
setNewPageSizeAndMargins
protected void setNewPageSizeAndMargins()
-
clearTextWrap
public void clearTextWrap()
Method added by Pelikan Stephan
-
add
protected void add(Image image) throws PdfException, DocumentException
Adds an image to the document.- Parameters:
image- theImageto add- Throws:
PdfException- on errorDocumentException- on error
-
analyzeRow
protected void analyzeRow(java.util.ArrayList rows, PdfDocument.RenderingContext ctx)
-
mayBeRemoved
protected boolean mayBeRemoved(java.util.ArrayList row)
-
consumeRowspan
protected void consumeRowspan(java.util.ArrayList row, PdfDocument.RenderingContext ctx)
-
extractRows
protected java.util.ArrayList extractRows(java.util.ArrayList cells, PdfDocument.RenderingContext ctx)
-
renderCells
protected void renderCells(PdfDocument.RenderingContext ctx, java.util.List cells, boolean hasToFit) throws DocumentException
- Throws:
DocumentException
-
doFooter
protected void doFooter() throws DocumentException- Throws:
DocumentException
-
doHeader
protected void doHeader() throws DocumentException- Throws:
DocumentException
-
-