Class PdfDocument
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.Document
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfDocument
-
- All Implemented Interfaces:
DocListener,ElementListener,java.util.EventListener
class PdfDocument extends Document implements DocListener
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.- See Also:
Document,DocListener,PdfWriter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPdfDocument.PdfCatalogPdfCatalogis the PDF Catalog-object.static classPdfDocument.PdfInfoPdfInfois the PDF InfoDictionary.
-
Field Summary
Fields Modifier and Type Field Description private PdfAcroFormacroFormThis is the AcroForm object.private PdfDictionaryadditionalActionsprivate intalignmentThis represents the current alignment of the PDF Elements.private java.util.ArrayListannotationsThis is the array containing the references to the annotations.protected java.util.HashMapboxSizeThis is the size of the several boxes that will be used in the next page.private PdfActioncurrentActionThe current activePdfActionwhen processing anAnchor.private floatcurrentHeightThis is the current height of the document.private PdfOutlinecurrentOutlineThis is the currentPdfOutlinein the hierarchy of outlines.private java.util.ArrayListdelayedAnnotationsThis is an array containg references to some delayed annotations.private java.util.ArrayListdocumentJavaScriptprotected intdurationThe duration of the pageprivate booleanfirstPageEventSignals that OnOpenDocument should be called.private PdfContentBytegraphicsThis is the PdfContentByte object, containing the borders and other Graphics.(package private) static java.lang.StringhangingPunctuationThe characters to be applied the hanging ponctuation.private floatimageEndThis is the position where the image ends.private floatimageIndentLeftThis is the indentation caused by an image on the left.private floatimageIndentRightThis is the indentation caused by an image on the right.private floatindentBottomThis represents the current indentation of the PDF Elements on the bottom side.private floatindentLeftThis represents the current indentation of the PDF Elements on the left side.private floatindentRightThis represents the current indentation of the PDF Elements on the right side.private floatindentTopThis represents the current indentation of the PDF Elements on the top side.private PdfDocument.PdfInfoinfosome meta information about the Document.private booleanisNewpageprivate booleanisParagraphSignals that onParagraph is valid.private intlastElementTypeHolds the type of the last element, that has been added to the document.private floatleadingThis represents the leading of the lines.private PdfLinelineThe line that is currently being written.private java.util.ArrayListlinesThe lines that are written until now.private floatlistIndentLeftThis represents the current indentation of the PDF Elements on the left side.private 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.private PdfActionopenActionActionprivate java.lang.StringopenActionNameprotected PdfDictionarypageAAprivate booleanpageEmptyThis checks if the page is empty.private PdfPageLabelspageLabelsprotected PageResourcespageResourcesThis are the page resources of the current Page.private floatparaIndentprivate PdfOutlinerootOutlineThis is the root outline of the document.private booleanstrictImageSequenceHolds value of property strictImageSequence.private PdfContentBytetextThis is the PdfContentByte object, containing the text.private inttextEmptySizeprotected java.util.HashMapthisBoxSizeThis is the size of the several boxes of the current Page.private PdfIndirectReferencethumbprotected PdfTransitiontransitionThe page transitionprivate intviewerPreferencesthese are the viewerpreferences of the documentprivate PdfWriterwriterThePdfWriter.-
Fields inherited from class com.gitlab.pdftk_java.com.lowagie.text.Document
close, compress, htmlStyleClass, javaScript_onLoad, javaScript_onUnLoad, marginBottom, marginLeft, marginMirroring, marginRight, marginTop, open, pageN, pageSize
-
-
Constructor Summary
Constructors Constructor Description PdfDocument()Constructs a new PDF document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Element element)Signals that anElementwas added to theDocument.(package private) voidaddAdditionalAction(PdfName actionType, PdfAction action)(package private) voidaddAnnotation(PdfAnnotation annot)(package private) voidaddCalculationOrder(PdfFormField formField)(package private) voidaddFormFieldRaw(PdfFormField field)(package private) voidaddJavaScript(PdfAction js)(package private) voidaddOutline(PdfOutline outline, java.lang.String name)Adds a named outline to the document .(package private) voidcalculateOutlineCount()private 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.voidclose()Closes the document.(package private) static PdfAnnotationconvertAnnotation(PdfWriter writer, Annotation annot)private voidensureNewLine()Ensures that a new line has been started.private floatflushLines()Writes all the lines to the text-object.PdfAcroFormgetAcroForm()Gets the AcroForm object.(package private) PdfDocument.PdfCataloggetCatalog(PdfIndirectReference pages)Gets thePdfCatalog-object.(package private) java.util.ArrayListgetDocumentJavaScript()Method added by Pelikan Stephan(package private) PdfDocument.PdfInfogetInfo()Gets thePdfInfo-object.(package private) PdfActiongetLocalGotoAction(java.lang.String name)(package private) intgetMarkPoint()(package private) PageResourcesgetPageResources()PdfOutlinegetRootOutline()Gets the root outline.floatgetVerticalPosition(boolean ensureNewLine)Gets the current vertical page position.(package private) voidincMarkPoint()(package private) floatindentBottom()Gets the indentation on the bottom side.private floatindentLeft()Gets the indentation on the left side.private floatindentRight()Gets the indentation on the right side.private floatindentTop()Gets the indentation on the top side.private voidinitPage()Initializes a page.(package private) booleanisStrictImageSequence()Getter for property strictImageSequence.(package private) booleanlocalDestination(java.lang.String name, PdfDestination destination)The local destination to where a local goto with the same name will jump to.(package private) voidlocalGoto(java.lang.String name, float llx, float lly, float urx, float ury)Implements a link to other part of the document.private 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.(package private) voidoutlineTree(PdfOutline outline)(package private) voidremoteGoto(java.lang.String filename, int page, float llx, float lly, float urx, float ury)Implements a link to another document.(package private) voidremoteGoto(java.lang.String filename, java.lang.String name, float llx, float lly, float urx, float ury)Implements a link to another document.voidresetPageCount()Sets the page number to 0.protected PdfArrayrotateAnnotations()(package private) voidsetAction(PdfAction action, float llx, float lly, float urx, float ury)Implements an action in an area.(package private) voidsetBoxSize(java.lang.String boxName, Rectangle size)(package private) voidsetCropBoxSize(Rectangle crop)(package private) voidsetDuration(int seconds)Sets the display duration for the page (for presentations)booleansetMarginMirroring(boolean MarginMirroring)Set the margin mirroring.booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)Sets the margins.(package private) voidsetOpenAction(PdfAction action)(package private) voidsetOpenAction(java.lang.String name)(package private) voidsetPageAction(PdfName actionType, PdfAction action)voidsetPageCount(int pageN)Sets the page number.(package private) voidsetPageEmpty(boolean pageEmpty)(package private) voidsetPageLabels(PdfPageLabels pageLabels)booleansetPageSize(Rectangle pageSize)Sets the pagesize.(package private) voidsetSigFlags(int f)(package private) voidsetStrictImageSequence(boolean strictImageSequence)Setter for property strictImageSequence.(package private) voidsetTransition(PdfTransition transition)Sets the transition for the pagevoidsetViewerPreferences(int preferences)Sets the viewer preferences as the sum of several constants.voidsetWriter(PdfWriter writer)Adds aPdfWriterto thePdfDocument.(package private) voidtraverseOutlineCount(PdfOutline outline)(package private) voidwriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, java.lang.Object[] currentValues, float ratio)Writes a text line to the document.(package private) voidwriteOutlines()-
Methods inherited from class com.gitlab.pdftk_java.com.lowagie.text.Document
addAuthor, addCreationDate, addCreator, addDocListener, addHeader, addKeywords, addProducer, addSubject, addTitle, bottom, bottom, bottomMargin, clearTextWrap, getHtmlStyleClass, getJavaScript_onLoad, getJavaScript_onUnLoad, getPageNumber, getPageSize, getVersion, isMarginMirroring, isOpen, left, left, leftMargin, removeDocListener, right, right, rightMargin, setHtmlStyleClass, setJavaScript_onLoad, setJavaScript_onUnLoad, top, top, topMargin
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.gitlab.pdftk_java.com.lowagie.text.DocListener
clearTextWrap
-
-
-
-
Field Detail
-
thumb
private PdfIndirectReference thumb
-
hangingPunctuation
static final java.lang.String hangingPunctuation
The characters to be applied the hanging ponctuation.- See Also:
- Constant Field Values
-
writer
private PdfWriter writer
ThePdfWriter.
-
info
private PdfDocument.PdfInfo info
some meta information about the Document.
-
firstPageEvent
private boolean firstPageEvent
Signals that OnOpenDocument should be called.
-
isParagraph
private boolean isParagraph
Signals that onParagraph is valid.
-
line
private PdfLine line
The line that is currently being written.
-
indentLeft
private float indentLeft
This represents the current indentation of the PDF Elements on the left side.
-
indentRight
private float indentRight
This represents the current indentation of the PDF Elements on the right side.
-
listIndentLeft
private float listIndentLeft
This represents the current indentation of the PDF Elements on the left side.
-
alignment
private int alignment
This represents the current alignment of the PDF Elements.
-
text
private PdfContentByte text
This is the PdfContentByte object, containing the text.
-
graphics
private PdfContentByte graphics
This is the PdfContentByte object, containing the borders and other Graphics.
-
lines
private java.util.ArrayList lines
The lines that are written until now.
-
leading
private float leading
This represents the leading of the lines.
-
currentHeight
private float currentHeight
This is the current height of the document.
-
indentTop
private float indentTop
This represents the current indentation of the PDF Elements on the top side.
-
indentBottom
private float indentBottom
This represents the current indentation of the PDF Elements on the bottom side.
-
pageEmpty
private boolean pageEmpty
This checks if the page is empty.
-
textEmptySize
private int textEmptySize
-
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.
-
pageResources
protected PageResources pageResources
This are the page resources of the current Page.
-
imageEnd
private float imageEnd
This is the position where the image ends.
-
imageIndentLeft
private float imageIndentLeft
This is the indentation caused by an image on the left.
-
imageIndentRight
private float imageIndentRight
This is the indentation caused by an image on the right.
-
annotations
private java.util.ArrayList annotations
This is the array containing the references to the annotations.
-
delayedAnnotations
private java.util.ArrayList delayedAnnotations
This is an array containg references to some delayed annotations.
-
acroForm
private PdfAcroForm acroForm
This is the AcroForm object.
-
rootOutline
private PdfOutline rootOutline
This is the root outline of the document.
-
currentOutline
private PdfOutline currentOutline
This is the currentPdfOutlinein the hierarchy of outlines.
-
currentAction
private PdfAction currentAction
The current activePdfActionwhen processing anAnchor.
-
localDestinations
private java.util.TreeMap localDestinations
Stores the destinations keyed by name. Value isObject[]{PdfAction,PdfIndirectReference,PdfDestintion}.
-
documentJavaScript
private java.util.ArrayList documentJavaScript
-
viewerPreferences
private int viewerPreferences
these are the viewerpreferences of the document
-
openActionName
private java.lang.String openActionName
-
openActionAction
private PdfAction openActionAction
-
additionalActions
private PdfDictionary additionalActions
-
pageLabels
private PdfPageLabels pageLabels
-
isNewpage
private boolean isNewpage
-
paraIndent
private float paraIndent
-
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
-
duration
protected int duration
The duration of the page
-
transition
protected PdfTransition transition
The page transition
-
pageAA
protected PdfDictionary pageAA
-
strictImageSequence
private boolean strictImageSequence
Holds value of property strictImageSequence.
-
lastElementType
private int lastElementType
Holds the type of the last element, that has been added to the document.
-
markPoint
protected int markPoint
-
-
Constructor Detail
-
PdfDocument
public PdfDocument()
Constructs a new PDF document.- Throws:
DocumentException- on error
-
-
Method Detail
-
setWriter
public void setWriter(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
-
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
-
resetPageCount
public void resetPageCount()
Sets the page number to 0.- Specified by:
resetPageCountin interfaceDocListener- Overrides:
resetPageCountin classDocument
-
setPageCount
public void setPageCount(int pageN)
Sets the page number.- Specified by:
setPageCountin interfaceDocListener- Overrides:
setPageCountin classDocument- Parameters:
pageN- the new page number
-
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
-
rotateAnnotations
protected PdfArray rotateAnnotations() throws DocumentException
- Throws:
DocumentException
-
newPage
public boolean newPage() throws DocumentExceptionMakes a new page and sends it to thePdfWriter.- Specified by:
newPagein interfaceDocListener- Overrides:
newPagein classDocument- Returns:
- a
boolean - Throws:
DocumentException- on error
-
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
-
outlineTree
void outlineTree(PdfOutline outline) throws java.io.IOException
- Throws:
java.io.IOException
-
writeOutlines
void writeOutlines() throws java.io.IOException- Throws:
java.io.IOException
-
traverseOutlineCount
void traverseOutlineCount(PdfOutline outline)
-
calculateOutlineCount
void calculateOutlineCount()
-
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
-
getPageResources
PageResources getPageResources()
-
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
-
initPage
private void initPage() throws DocumentExceptionInitializes a page.If the footer/header is set, it is printed.
- Throws:
DocumentException- on error
-
carriageReturn
private void carriageReturn() throws DocumentExceptionIf the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.- Throws:
DocumentException- on error
-
newLine
private void newLine() throws DocumentExceptionAdds the current line to the list of lines and also adds an empty line.- Throws:
DocumentException- on error
-
flushLines
private float flushLines() throws DocumentExceptionWrites all the lines to the text-object.- Returns:
- the displacement that was caused
- Throws:
DocumentException- on error
-
getInfo
PdfDocument.PdfInfo getInfo()
Gets thePdfInfo-object.- Returns:
PdfInfo
-
getCatalog
PdfDocument.PdfCatalog getCatalog(PdfIndirectReference pages) throws DocumentException
Gets thePdfCatalog-object.- Parameters:
pages- an indirect reference to this document pages- Returns:
PdfCatalog- Throws:
DocumentException
-
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
private void ensureNewLine()
Ensures that a new line has been started.
-
indentLeft
private float indentLeft()
Gets the indentation on the left side.- Returns:
- a margin
-
indentRight
private float indentRight()
Gets the indentation on the right side.- Returns:
- a margin
-
indentTop
private float indentTop()
Gets the indentation on the top side.- Returns:
- a margin
-
indentBottom
float indentBottom()
Gets the indentation on the bottom side.- Returns:
- a margin
-
addOutline
void addOutline(PdfOutline outline, java.lang.String name)
Adds a named outline to the document .- Parameters:
outline- the outline to be addedname- the name of this local destination
-
getAcroForm
public PdfAcroForm getAcroForm() throws DocumentException
Gets the AcroForm object.- Returns:
- the PdfAcroform object of the PdfDocument
- Throws:
DocumentException
-
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
-
writeLineToContent
void writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, java.lang.Object[] currentValues, float ratio) throws DocumentException
Writes a text line to the document. It takes care of all the attributes.Before entering the line position must have been established and the
textargument must be in text object scope (beginText()).- Parameters:
line- the line to be writtentext- thePdfContentBytewhere the text will be written tographics- thePdfContentBytewhere the graphics will be written tocurrentValues- the current font and extra spacing valuesratio-- Throws:
DocumentException- on error
-
localGoto
void localGoto(java.lang.String name, float llx, float lly, float urx, float ury)Implements a link to other part of the document. The jump will be made to a local destination with the same name, that must exist.- Parameters:
name- the name for this linkllx- the lower left x corner of the activation areally- the lower left y corner of the activation areaurx- the upper right x corner of the activation areaury- the upper right y corner of the activation area
-
getLocalGotoAction
PdfAction getLocalGotoAction(java.lang.String name)
-
localDestination
boolean localDestination(java.lang.String name, PdfDestination destination)The local destination to where a local goto with the same name will jump to.- Parameters:
name- the name of this local destinationdestination- thePdfDestinationwith the jump coordinates- Returns:
trueif the local destination was added,falseif a local destination with the same name already existed
-
remoteGoto
void remoteGoto(java.lang.String filename, java.lang.String name, float llx, float lly, float urx, float ury)Implements a link to another document.- Parameters:
filename- the filename for the remote documentname- the name to jump tollx- the lower left x corner of the activation areally- the lower left y corner of the activation areaurx- the upper right x corner of the activation areaury- the upper right y corner of the activation area
-
remoteGoto
void remoteGoto(java.lang.String filename, int page, float llx, float lly, float urx, float ury)Implements a link to another document.- Parameters:
filename- the filename for the remote documentpage- the page to jump tollx- the lower left x corner of the activation areally- the lower left y corner of the activation areaurx- the upper right x corner of the activation areaury- the upper right y corner of the activation area
-
setViewerPreferences
public void setViewerPreferences(int preferences)
Sets the viewer preferences as the sum of several constants.- Parameters:
preferences- the viewer preferences- See Also:
PdfWriter.setViewerPreferences(int)
-
setAction
void setAction(PdfAction action, float llx, float lly, float urx, float ury)
Implements an action in an area.- Parameters:
action- thePdfActionllx- the lower left x corner of the activation areally- the lower left y corner of the activation areaurx- the upper right x corner of the activation areaury- the upper right y corner of the activation area
-
setOpenAction
void setOpenAction(java.lang.String name)
-
setOpenAction
void setOpenAction(PdfAction action)
-
setPageLabels
void setPageLabels(PdfPageLabels pageLabels)
-
addJavaScript
void addJavaScript(PdfAction js)
-
setCropBoxSize
void setCropBoxSize(Rectangle crop)
-
setBoxSize
void setBoxSize(java.lang.String boxName, Rectangle size)
-
addCalculationOrder
void addCalculationOrder(PdfFormField formField) throws DocumentException
- Throws:
DocumentException
-
setSigFlags
void setSigFlags(int f) throws DocumentException- Throws:
DocumentException
-
addFormFieldRaw
void addFormFieldRaw(PdfFormField field)
-
addAnnotation
void addAnnotation(PdfAnnotation annot)
-
setDuration
void setDuration(int seconds)
Sets the display duration for the page (for presentations)- Parameters:
seconds- the number of seconds to display the page
-
setTransition
void setTransition(PdfTransition transition)
Sets the transition for the page- Parameters:
transition- the PdfTransition object
-
isStrictImageSequence
boolean isStrictImageSequence()
Getter for property strictImageSequence.- Returns:
- Value of property strictImageSequence.
-
setStrictImageSequence
void setStrictImageSequence(boolean strictImageSequence)
Setter for property strictImageSequence.- Parameters:
strictImageSequence- New value of property strictImageSequence.
-
setPageEmpty
void setPageEmpty(boolean pageEmpty)
-
getDocumentJavaScript
java.util.ArrayList getDocumentJavaScript()
Method added by Pelikan Stephan- See Also:
DocListener.clearTextWrap()
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring)
Description copied from class:DocumentSet the margin mirroring. It will mirror 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)
-
convertAnnotation
static PdfAnnotation convertAnnotation(PdfWriter writer, Annotation annot) throws java.io.IOException
- Throws:
java.io.IOException
-
getMarkPoint
int getMarkPoint()
- Returns:
- an XmpMetadata byte array
-
incMarkPoint
void incMarkPoint()
-
-