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
,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
.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
PdfCatalog
is the PDF Catalog-object.static class
PdfInfo
is the PDF InfoDictionary. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PdfAcroForm
This is the AcroForm object.private PdfDictionary
private int
This represents the current alignment of the PDF Elements.private ArrayList
This is the array containing the references to the annotations.protected HashMap
This is the size of the several boxes that will be used in the next page.private PdfAction
The current activePdfAction
when processing anAnchor
.private float
This is the current height of the document.private PdfOutline
This is the currentPdfOutline
in the hierarchy of outlines.private ArrayList
This is an array containg references to some delayed annotations.private ArrayList
protected int
The duration of the pageprivate boolean
Signals that OnOpenDocument should be called.private PdfContentByte
This is the PdfContentByte object, containing the borders and other Graphics.(package private) static final String
The characters to be applied the hanging ponctuation.private float
This is the position where the image ends.private float
This is the indentation caused by an image on the left.private float
This is the indentation caused by an image on the right.private float
This represents the current indentation of the PDF Elements on the bottom side.private float
This represents the current indentation of the PDF Elements on the left side.private float
This represents the current indentation of the PDF Elements on the right side.private float
This represents the current indentation of the PDF Elements on the top side.private PdfDocument.PdfInfo
some meta information about the Document.private boolean
private boolean
Signals that onParagraph is valid.private int
Holds the type of the last element, that has been added to the document.private float
This represents the leading of the lines.private PdfLine
The line that is currently being written.private ArrayList
The lines that are written until now.private float
This represents the current indentation of the PDF Elements on the left side.private TreeMap
Stores the destinations keyed by name.protected int
protected float
margin in y direction starting from the bottom.protected float
margin in x direction starting from the left.protected float
margin in x direction starting from the right.protected float
margin in y direction starting from the top.protected Rectangle
This is the size of the next page.private PdfAction
private String
protected PdfDictionary
private boolean
This checks if the page is empty.private PdfPageLabels
protected PageResources
This are the page resources of the current Page.private float
private PdfOutline
This is the root outline of the document.private boolean
Holds value of property strictImageSequence.private PdfContentByte
This is the PdfContentByte object, containing the text.private int
protected HashMap
This is the size of the several boxes of the current Page.private PdfIndirectReference
protected PdfTransition
The page transitionprivate int
these are the viewerpreferences of the documentprivate PdfWriter
ThePdfWriter
.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 -
Method Summary
Modifier and TypeMethodDescriptionboolean
Signals that anElement
was added to theDocument
.(package private) void
addAdditionalAction
(PdfName actionType, PdfAction action) (package private) void
addAnnotation
(PdfAnnotation annot) (package private) void
addCalculationOrder
(PdfFormField formField) (package private) void
addFormFieldRaw
(PdfFormField field) (package private) void
(package private) void
addOutline
(PdfOutline outline, String name) Adds a named outline to the document .(package private) void
private void
If the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.void
close()
Closes the document.(package private) static PdfAnnotation
convertAnnotation
(PdfWriter writer, Annotation annot) private void
Ensures that a new line has been started.private float
Writes all the lines to the text-object.Gets the AcroForm object.(package private) PdfDocument.PdfCatalog
getCatalog
(PdfIndirectReference pages) Gets thePdfCatalog
-object.(package private) ArrayList
Method added by Pelikan Stephan(package private) PdfDocument.PdfInfo
getInfo()
Gets thePdfInfo
-object.(package private) PdfAction
getLocalGotoAction
(String name) (package private) int
(package private) PageResources
Gets the root outline.float
getVerticalPosition
(boolean ensureNewLine) Gets the current vertical page position.(package private) void
(package private) float
Gets the indentation on the bottom side.private float
Gets the indentation on the left side.private float
Gets the indentation on the right side.private float
Gets the indentation on the top side.private void
initPage()
Initializes a page.(package private) boolean
Getter for property strictImageSequence.(package private) boolean
localDestination
(String name, PdfDestination destination) The local destination to where a local goto with the same name will jump to.(package private) void
Implements a link to other part of the document.private void
newLine()
Adds the current line to the list of lines and also adds an empty line.boolean
newPage()
Makes a new page and sends it to thePdfWriter
.void
open()
Opens the document.(package private) void
outlineTree
(PdfOutline outline) (package private) void
remoteGoto
(String filename, int page, float llx, float lly, float urx, float ury) Implements a link to another document.(package private) void
remoteGoto
(String filename, String name, float llx, float lly, float urx, float ury) Implements a link to another document.void
Sets the page number to 0.protected PdfArray
(package private) void
Implements an action in an area.(package private) void
setBoxSize
(String boxName, Rectangle size) (package private) void
setCropBoxSize
(Rectangle crop) (package private) void
setDuration
(int seconds) Sets the display duration for the page (for presentations)boolean
setMarginMirroring
(boolean MarginMirroring) Set the margin mirroring.boolean
setMargins
(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.(package private) void
setOpenAction
(PdfAction action) (package private) void
setOpenAction
(String name) (package private) void
setPageAction
(PdfName actionType, PdfAction action) void
setPageCount
(int pageN) Sets the page number.(package private) void
setPageEmpty
(boolean pageEmpty) (package private) void
setPageLabels
(PdfPageLabels pageLabels) boolean
setPageSize
(Rectangle pageSize) Sets the pagesize.(package private) void
setSigFlags
(int f) (package private) void
setStrictImageSequence
(boolean strictImageSequence) Setter for property strictImageSequence.(package private) void
setTransition
(PdfTransition transition) Sets the transition for the pagevoid
setViewerPreferences
(int preferences) Sets the viewer preferences as the sum of several constants.void
Adds aPdfWriter
to thePdfDocument
.(package private) void
traverseOutlineCount
(PdfOutline outline) (package private) void
writeLineToContent
(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio) Writes a text line to the document.(package private) void
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 Details
-
thumb
-
hangingPunctuation
The characters to be applied the hanging ponctuation.- See Also:
-
writer
ThePdfWriter
. -
info
some meta information about the Document. -
firstPageEvent
private boolean firstPageEventSignals that OnOpenDocument should be called. -
isParagraph
private boolean isParagraphSignals that onParagraph is valid. -
line
The line that is currently being written. -
indentLeft
private float indentLeftThis represents the current indentation of the PDF Elements on the left side. -
indentRight
private float indentRightThis represents the current indentation of the PDF Elements on the right side. -
listIndentLeft
private float listIndentLeftThis represents the current indentation of the PDF Elements on the left side. -
alignment
private int alignmentThis represents the current alignment of the PDF Elements. -
text
This is the PdfContentByte object, containing the text. -
graphics
This is the PdfContentByte object, containing the borders and other Graphics. -
lines
The lines that are written until now. -
leading
private float leadingThis represents the leading of the lines. -
currentHeight
private float currentHeightThis is the current height of the document. -
indentTop
private float indentTopThis represents the current indentation of the PDF Elements on the top side. -
indentBottom
private float indentBottomThis represents the current indentation of the PDF Elements on the bottom side. -
pageEmpty
private boolean pageEmptyThis checks if the page is empty. -
textEmptySize
private int textEmptySize -
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. -
pageResources
This are the page resources of the current Page. -
imageEnd
private float imageEndThis is the position where the image ends. -
imageIndentLeft
private float imageIndentLeftThis is the indentation caused by an image on the left. -
imageIndentRight
private float imageIndentRightThis is the indentation caused by an image on the right. -
annotations
This is the array containing the references to the annotations. -
delayedAnnotations
This is an array containg references to some delayed annotations. -
acroForm
This is the AcroForm object. -
rootOutline
This is the root outline of the document. -
currentOutline
This is the currentPdfOutline
in the hierarchy of outlines. -
currentAction
The current activePdfAction
when processing anAnchor
. -
localDestinations
Stores the destinations keyed by name. Value isObject[]{PdfAction,PdfIndirectReference,PdfDestintion}
. -
documentJavaScript
-
viewerPreferences
private int viewerPreferencesthese are the viewerpreferences of the document -
openActionName
-
openActionAction
-
additionalActions
-
pageLabels
-
isNewpage
private boolean isNewpage -
paraIndent
private float paraIndent -
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 -
duration
protected int durationThe duration of the page -
transition
The page transition -
pageAA
-
strictImageSequence
private boolean strictImageSequenceHolds value of property strictImageSequence. -
lastElementType
private int lastElementTypeHolds the type of the last element, that has been added to the document. -
markPoint
protected int markPoint
-
-
Constructor Details
-
PdfDocument
public PdfDocument()Constructs a new PDF document.- Throws:
DocumentException
- on error
-
-
Method Details
-
setWriter
Adds aPdfWriter
to thePdfDocument
.- Parameters:
writer
- thePdfWriter
that writes everything what is added to this document to an outputstream.- Throws:
DocumentException
- on error
-
setPageSize
Sets the pagesize.- Specified by:
setPageSize
in interfaceDocListener
- Overrides:
setPageSize
in classDocument
- Parameters:
pageSize
- the new pagesize- Returns:
true
if the page size was set
-
resetPageCount
public void resetPageCount()Sets the page number to 0.- Specified by:
resetPageCount
in interfaceDocListener
- Overrides:
resetPageCount
in classDocument
-
setPageCount
public void setPageCount(int pageN) Sets the page number.- Specified by:
setPageCount
in interfaceDocListener
- Overrides:
setPageCount
in classDocument
- Parameters:
pageN
- the new page number
-
setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.- Specified by:
setMargins
in interfaceDocListener
- Overrides:
setMargins
in 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
- Throws:
DocumentException
-
newPage
Makes a new page and sends it to thePdfWriter
.- Specified by:
newPage
in interfaceDocListener
- Overrides:
newPage
in 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:
open
in interfaceDocListener
- Overrides:
open
in classDocument
-
outlineTree
- Throws:
IOException
-
writeOutlines
- Throws:
IOException
-
traverseOutlineCount
-
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:
close
in interfaceDocListener
- Overrides:
close
in classDocument
-
getPageResources
PageResources getPageResources() -
add
Signals that anElement
was added to theDocument
.- Specified by:
add
in interfaceElementListener
- Overrides:
add
in classDocument
- Parameters:
element
- the element to add- Returns:
true
if the element was added,false
if not.- Throws:
DocumentException
- when a document isn't open yet, or has been closed
-
initPage
Initializes a page.If the footer/header is set, it is printed.
- Throws:
DocumentException
- on error
-
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.- Throws:
DocumentException
- on error
-
newLine
Adds the current line to the list of lines and also adds an empty line.- Throws:
DocumentException
- on error
-
flushLines
Writes 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
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
Adds a named outline to the document .- Parameters:
outline
- the outline to be addedname
- the name of this local destination
-
getAcroForm
Gets the AcroForm object.- Returns:
- the PdfAcroform object of the PdfDocument
- Throws:
DocumentException
-
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, 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
text
argument must be in text object scope (beginText()
).- Parameters:
line
- the line to be writtentext
- thePdfContentByte
where the text will be written tographics
- thePdfContentByte
where the graphics will be written tocurrentValues
- the current font and extra spacing valuesratio
-- Throws:
DocumentException
- on error
-
localGoto
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
-
localDestination
The local destination to where a local goto with the same name will jump to.- Parameters:
name
- the name of this local destinationdestination
- thePdfDestination
with the jump coordinates- Returns:
true
if the local destination was added,false
if a local destination with the same name already existed
-
remoteGoto
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
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:
-
setAction
Implements an action in an area.- Parameters:
action
- thePdfAction
llx
- 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
-
setOpenAction
-
addAdditionalAction
-
setPageLabels
-
addJavaScript
-
setCropBoxSize
-
setBoxSize
-
addCalculationOrder
- Throws:
DocumentException
-
setSigFlags
- Throws:
DocumentException
-
addFormFieldRaw
-
addAnnotation
-
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
Sets the transition for the page- Parameters:
transition
- the PdfTransition object
-
setPageAction
-
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
ArrayList getDocumentJavaScript()Method added by Pelikan Stephan- See Also:
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring) Description copied from class:Document
Set the margin mirroring. It will mirror margins for odd/even pages.Note: it will not work with
Table
.- Specified by:
setMarginMirroring
in interfaceDocListener
- Overrides:
setMarginMirroring
in classDocument
- Parameters:
MarginMirroring
-true
to mirror the margins- Returns:
- always
true
- See Also:
-
convertAnnotation
- Throws:
IOException
-
getMarkPoint
int getMarkPoint()- Returns:
- an XmpMetadata byte array
-
incMarkPoint
void incMarkPoint()
-