Package com.lowagie.text.pdf
Class PdfDocument
java.lang.Object
com.lowagie.text.Document
com.lowagie.text.pdf.PdfDocument
- All Implemented Interfaces:
DocListener,ElementListener,EventListener
PdfDocument is the class that is used by PdfWriter
to translate a Document into a PDF with different pages.
A PdfDocument always listens to a Document
and adds the Pdf representation of every Element that is
added to the Document.
- Since:
- 2.0.8 (class was package-private before)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classPdfInfois the PDF InfoDictionary.protected static classThis is a helper class for adding a Table to a document. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PdfDictionaryprotected intThis represents the current alignment of the PDF Elements.protected PdfActionThe current activePdfActionwhen processing anAnchor.protected HashMapThis is the size of the several boxes that will be used in the next page.protected PdfCollectionprotected floatThis is the current height of the document.protected PdfOutlineThis is the currentPdfOutlinein the hierarchy of outlines.protected HashMapprotected HashMapprotected intThe duration of the pageprotected booleanSignals that OnOpenDocument should be called.protected PdfContentByteThis is the PdfContentByte object, containing the borders and other Graphics.protected floatThis is the position where the image ends.protected ImageThis is the image that could not be shown on a previous page.protected PdfDocument.Indentationprotected PdfDocument.PdfInfosome meta information about the Document.protected booleanSignals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).protected intHolds the type of the last element, that has been added to the document.protected floatThis represents the leading of the lines.protected intSignals that the current leading has to be subtracted from a YMark object when positive.protected PdfLineThe line that is currently being written.protected ArrayListThe lines that are written until now.protected TreeMapStores the destinations keyed by name.protected intprotected floatmargin in y direction starting from the bottom.protected floatmargin in x direction starting from the left.protected floatmargin in x direction starting from the right.protected floatmargin in y direction starting from the top.protected RectangleThis is the size of the next page.protected PdfActionprotected Stringprotected PdfDictionaryprotected PdfPageLabelsprotected com.lowagie.text.pdf.PageResourcesThis are the page resources of the current Page.protected PdfOutlineThis is the root outline of the document.protected static final DecimalFormatprotected booleanHolds value of property strictImageSequence.protected PdfContentByteThis is the PdfContentByte object, containing the text.protected intprotected HashMapThis is the size of the several boxes of the current Page.protected PdfIndirectReferenceprotected PdfTransitionThe page transitionprotected PdfViewerPreferencesImpContains the Viewer preferences of this PDF document.protected PdfWriterThePdfWriter.protected byte[]XMP Metadata for the page.Fields inherited from class com.lowagie.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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanSignals that anElementwas added to theDocument.protected voidAdds an image to the document.protected voidaddSpacing(float extraspace, float oldleading, Font f) Adds extra space.voidAdds aPdfWriterto thePdfDocument.protected voidanalyzeRow(ArrayList rows, PdfDocument.RenderingContext ctx) protected voidIf the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.voidMethod added by Pelikan Stephanvoidclose()Closes the document.protected voidprotected voiddoFooter()protected voiddoHeader()protected voidEnsures that a new line has been started.protected ArrayListextractRows(ArrayList cells, PdfDocument.RenderingContext ctx) protected floatWrites all the lines to the text-object.floatGetter for the current leading.Gets the root outline.floatgetVerticalPosition(boolean ensureNewLine) Gets the current vertical page position.protected floatGets the indentation on the left side.protected floatGets the indentation on the right side.protected floatGets the indentation on the top side.protected voidinitPage()Initializes a page.protected booleanmayBeRemoved(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, List cells, boolean hasToFit) voidResets the footer of this document.voidResets the header of this document.voidSets 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 voidvoidsetPageCount(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.lowagie.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 Details
-
writer
ThePdfWriter. -
text
This is the PdfContentByte object, containing the text. -
graphics
This is the PdfContentByte object, containing the borders and other Graphics. -
leading
protected float leadingThis represents the leading of the lines. -
alignment
protected int alignmentThis represents the current alignment of the PDF Elements. -
currentHeight
protected float currentHeightThis is the current height of the document. -
isSectionTitle
protected boolean isSectionTitleSignals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).- Since:
- 2.1.2
-
leadingCount
protected int leadingCountSignals that the current leading has to be subtracted from a YMark object when positive.- Since:
- 2.1.2
-
anchorAction
The current activePdfActionwhen processing anAnchor. -
textEmptySize
protected int textEmptySize -
xmpMetadata
protected byte[] xmpMetadataXMP Metadata for the page. -
nextMarginLeft
protected float nextMarginLeftmargin in x direction starting from the left. Will be valid in the next page -
nextMarginRight
protected float nextMarginRightmargin in x direction starting from the right. Will be valid in the next page -
nextMarginTop
protected float nextMarginTopmargin in y direction starting from the top. Will be valid in the next page -
nextMarginBottom
protected float nextMarginBottommargin in y direction starting from the bottom. Will be valid in the next page -
firstPageEvent
protected boolean firstPageEventSignals that OnOpenDocument should be called. -
line
The line that is currently being written. -
lines
The lines that are written until now. -
lastElementType
protected int lastElementTypeHolds the type of the last element, that has been added to the document. -
indentation
-
info
some meta information about the Document. -
rootOutline
This is the root outline of the document. -
currentOutline
This is the currentPdfOutlinein the hierarchy of outlines. -
viewerPreferences
Contains the Viewer preferences of this PDF document. -
pageLabels
-
localDestinations
Stores the destinations keyed by name. Value isObject[]{PdfAction,PdfIndirectReference,PdfDestintion}. -
documentLevelJS
-
SIXTEEN_DIGITS
-
documentFileAttachment
-
openActionName
-
openActionAction
-
additionalActions
-
collection
-
markPoint
protected int markPoint -
nextPageSize
This is the size of the next page. -
thisBoxSize
This is the size of the several boxes of the current Page. -
boxSize
This is the size of the several boxes that will be used in the next page. -
duration
protected int durationThe duration of the page -
transition
The page transition -
pageAA
-
thumb
-
pageResources
protected com.lowagie.text.pdf.PageResources pageResourcesThis are the page resources of the current Page. -
strictImageSequence
protected boolean strictImageSequenceHolds value of property strictImageSequence. -
imageEnd
protected float imageEndThis is the position where the image ends. -
imageWait
This is the image that could not be shown on a previous page.
-
-
Constructor Details
-
PdfDocument
public PdfDocument()Constructs a new PDF document.
-
-
Method Details
-
addWriter
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
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
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:
-
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:
-
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
-
resetHeader
public void resetHeader()Resets the header of this document.- Specified by:
resetHeaderin interfaceDocListener- Overrides:
resetHeaderin classDocument
-
initPage
Initializes a page.If the footer/header is set, it is printed.
- Throws:
DocumentException- on error
-
newLine
Adds 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
Writes 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
Adds extra space. This method should probably be rewritten. -
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
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
Adds an image to the document.- Parameters:
image- theImageto add- Throws:
PdfException- on errorDocumentException- on error
-
analyzeRow
-
mayBeRemoved
-
consumeRowspan
-
extractRows
-
renderCells
protected void renderCells(PdfDocument.RenderingContext ctx, List cells, boolean hasToFit) throws DocumentException - Throws:
DocumentException
-
doHeader
- Throws:
DocumentException
-