Package com.itextpdf.text.pdf
Class PdfAnnotation
- java.lang.Object
-
- com.itextpdf.text.pdf.PdfObject
-
- com.itextpdf.text.pdf.PdfDictionary
-
- com.itextpdf.text.pdf.PdfAnnotation
-
- All Implemented Interfaces:
IAccessibleElement
,java.io.Serializable
- Direct Known Subclasses:
PdfFormField
public class PdfAnnotation extends PdfDictionary implements IAccessibleElement
APdfAnnotation
is a note that is associated with a page.- See Also:
PdfDictionary
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PdfAnnotation.PdfImportedLink
This class processes links from imported pages so that they may be active.
-
Field Summary
Fields Modifier and Type Field Description static PdfName
AA_BLUR
attributevaluestatic PdfName
AA_DOWN
attributevaluestatic PdfName
AA_ENTER
attributevaluestatic PdfName
AA_EXIT
attributevaluestatic PdfName
AA_FOCUS
attributevaluestatic PdfName
AA_JS_CHANGE
attributevaluestatic PdfName
AA_JS_FORMAT
attributevaluestatic PdfName
AA_JS_KEY
attributevaluestatic PdfName
AA_JS_OTHER_CHANGE
attributevaluestatic PdfName
AA_UP
attributevalueprotected java.util.HashMap<PdfName,PdfObject>
accessibleAttributes
protected boolean
annotation
static PdfName
APPEARANCE_DOWN
appearance attributenamestatic PdfName
APPEARANCE_NORMAL
appearance attributenamestatic PdfName
APPEARANCE_ROLLOVER
appearance attributenamestatic int
FLAGS_HIDDEN
flagvaluestatic int
FLAGS_INVISIBLE
flagvaluestatic int
FLAGS_LOCKED
flagvaluestatic int
FLAGS_LOCKEDCONTENTS
flagvalue PDF 1.7static int
FLAGS_NOROTATE
flagvaluestatic int
FLAGS_NOVIEW
flagvaluestatic int
FLAGS_NOZOOM
flagvaluestatic int
FLAGS_PRINT
flagvaluestatic int
FLAGS_READONLY
flagvaluestatic int
FLAGS_TOGGLENOVIEW
flagvalueprotected boolean
form
static PdfName
HIGHLIGHT_INVERT
highlight attributenamestatic PdfName
HIGHLIGHT_NONE
highlight attributenamestatic PdfName
HIGHLIGHT_OUTLINE
highlight attributenamestatic PdfName
HIGHLIGHT_PUSH
highlight attributenamestatic PdfName
HIGHLIGHT_TOGGLE
highlight attributenameprivate AccessibleElementId
id
static int
MARKUP_HIGHLIGHT
attributevaluestatic int
MARKUP_SQUIGGLY
attributevaluestatic int
MARKUP_STRIKEOUT
attributevaluestatic int
MARKUP_UNDERLINE
attributevalueprivate int
placeInPage
Holds value of property placeInPage.protected PdfIndirectReference
reference
Reference to this annotation.protected PdfName
role
protected java.util.HashSet<PdfTemplate>
templates
protected boolean
used
Holds value of property used.protected PdfWriter
writer
-
Constructor Summary
Constructors Constructor Description PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ury, PdfAction action)
Constructs a newPdfAnnotation
of subtype link (Action).PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ury, PdfString title, PdfString content)
Constructs a newPdfAnnotation
of subtype text.PdfAnnotation(PdfWriter writer, Rectangle rect)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyCTM(AffineTransform ctm)
static PdfAnnotation
createFileAttachment(PdfWriter writer, Rectangle rect, java.lang.String contents, byte[] fileStore, java.lang.String file, java.lang.String fileDisplay)
Creates a file attachment annotation.static PdfAnnotation
createFileAttachment(PdfWriter writer, Rectangle rect, java.lang.String contents, PdfFileSpecification fs)
Creates a file attachment annotationstatic PdfAnnotation
createFreeText(PdfWriter writer, Rectangle rect, java.lang.String contents, PdfContentByte defaultAppearance)
Add some free text to the document.static PdfAnnotation
createInk(PdfWriter writer, Rectangle rect, java.lang.String contents, float[][] inkList)
static PdfAnnotation
createLine(PdfWriter writer, Rectangle rect, java.lang.String contents, float x1, float y1, float x2, float y2)
Adds a line to the document.protected static PdfAnnotation
createLink(PdfWriter writer, Rectangle rect, PdfName highlight)
Creates a link.static PdfAnnotation
createLink(PdfWriter writer, Rectangle rect, PdfName highlight, int page, PdfDestination dest)
Creates an Annotation with a PdfDestination.static PdfAnnotation
createLink(PdfWriter writer, Rectangle rect, PdfName highlight, PdfAction action)
Creates an Annotation with an Action.static PdfAnnotation
createLink(PdfWriter writer, Rectangle rect, PdfName highlight, java.lang.String namedDestination)
Creates an Annotation with an local destination.static PdfAnnotation
createMarkup(PdfWriter writer, Rectangle rect, java.lang.String contents, int type, float[] quadPoints)
static PdfAnnotation
createPolygonPolyline(PdfWriter writer, Rectangle rect, java.lang.String contents, boolean polygon, PdfArray vertices)
Creates a polygon or -line annotationstatic PdfAnnotation
createPopup(PdfWriter writer, Rectangle rect, java.lang.String contents, boolean open)
Adds a popup to your document.static PdfAnnotation
createScreen(PdfWriter writer, Rectangle rect, java.lang.String clipTitle, PdfFileSpecification fs, java.lang.String mimeType, boolean playOnDisplay)
Creates a screen PdfAnnotationstatic PdfAnnotation
createSquareCircle(PdfWriter writer, Rectangle rect, java.lang.String contents, boolean square)
Adds a circle or a square that shows a tooltip when you pass over it.static PdfAnnotation
createStamp(PdfWriter writer, Rectangle rect, java.lang.String contents, java.lang.String name)
Adds a Stamp to your document.static PdfAnnotation
createText(PdfWriter writer, Rectangle rect, java.lang.String title, java.lang.String contents, boolean open, java.lang.String icon)
PdfObject
getAccessibleAttribute(PdfName key)
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).java.util.HashMap<PdfName,PdfObject>
getAccessibleAttributes()
Gets all the properties of accessible element.AccessibleElementId
getId()
PdfIndirectReference
getIndirectReference()
Returns an indirect reference to the annotation(package private) PdfDictionary
getMK()
static PdfArray
getMKColor(BaseColor color)
int
getPlaceInPage()
Getter for property placeInPage.PdfName
getRole()
Gets the role of the accessible element.java.util.HashSet<PdfTemplate>
getTemplates()
boolean
isAnnotation()
Getter for property annotation.boolean
isForm()
Getter for property form.boolean
isInline()
boolean
isUsed()
Getter for property used.void
setAccessibleAttribute(PdfName key, PdfObject value)
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).void
setAction(PdfAction action)
void
setAdditionalActions(PdfName key, PdfAction action)
void
setAppearance(PdfName ap, PdfTemplate template)
void
setAppearance(PdfName ap, java.lang.String state, PdfTemplate template)
void
setAppearanceState(java.lang.String state)
void
setBorder(PdfBorderArray border)
void
setBorderStyle(PdfBorderDictionary border)
void
setColor(BaseColor color)
void
setDefaultAppearanceString(PdfContentByte cb)
void
setFlags(int flags)
void
setHighlighting(PdfName highlight)
Sets the annotation's highlighting mode.void
setId(AccessibleElementId id)
void
setLayer(PdfOCG layer)
Sets the layer this annotation belongs to.void
setMKAlternateCaption(java.lang.String caption)
void
setMKAlternateIcon(PdfTemplate template)
void
setMKBackgroundColor(BaseColor color)
void
setMKBorderColor(BaseColor color)
void
setMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, boolean fitInBounds)
void
setMKNormalCaption(java.lang.String caption)
void
setMKNormalIcon(PdfTemplate template)
void
setMKRolloverCaption(java.lang.String caption)
void
setMKRolloverIcon(PdfTemplate template)
void
setMKRotation(int rotation)
void
setMKTextPosition(int tp)
void
setName(java.lang.String name)
Sets the name of the annotation.void
setPage()
void
setPage(int page)
void
setPlaceInPage(int placeInPage)
Places the annotation in a specified page that must be greater or equal to the current one.void
setPopup(PdfAnnotation popup)
void
setRole(PdfName role)
Sets the role of the accessiblee element.void
setRotate(int v)
void
setTitle(java.lang.String title)
void
setUsed()
Setter for property used.void
toPdf(PdfWriter writer, java.io.OutputStream os)
Writes the PDF representation of thisPdfDictionary
as an array ofbyte
to the givenOutputStream
.-
Methods inherited from class com.itextpdf.text.pdf.PdfDictionary
checkType, clear, contains, get, getAsArray, getAsBoolean, getAsDict, getAsIndirectObject, getAsName, getAsNumber, getAsStream, getAsString, getDirectObject, getKeys, isCatalog, isFont, isOutlineTree, isPage, isPages, merge, mergeDifferent, put, putAll, putEx, remove, size, toString
-
Methods inherited from class com.itextpdf.text.pdf.PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, type
-
-
-
-
Field Detail
-
HIGHLIGHT_NONE
public static final PdfName HIGHLIGHT_NONE
highlight attributename
-
HIGHLIGHT_INVERT
public static final PdfName HIGHLIGHT_INVERT
highlight attributename
-
HIGHLIGHT_OUTLINE
public static final PdfName HIGHLIGHT_OUTLINE
highlight attributename
-
HIGHLIGHT_PUSH
public static final PdfName HIGHLIGHT_PUSH
highlight attributename
-
HIGHLIGHT_TOGGLE
public static final PdfName HIGHLIGHT_TOGGLE
highlight attributename
-
FLAGS_INVISIBLE
public static final int FLAGS_INVISIBLE
flagvalue- See Also:
- Constant Field Values
-
FLAGS_HIDDEN
public static final int FLAGS_HIDDEN
flagvalue- See Also:
- Constant Field Values
-
FLAGS_PRINT
public static final int FLAGS_PRINT
flagvalue- See Also:
- Constant Field Values
-
FLAGS_NOZOOM
public static final int FLAGS_NOZOOM
flagvalue- See Also:
- Constant Field Values
-
FLAGS_NOROTATE
public static final int FLAGS_NOROTATE
flagvalue- See Also:
- Constant Field Values
-
FLAGS_NOVIEW
public static final int FLAGS_NOVIEW
flagvalue- See Also:
- Constant Field Values
-
FLAGS_READONLY
public static final int FLAGS_READONLY
flagvalue- See Also:
- Constant Field Values
-
FLAGS_LOCKED
public static final int FLAGS_LOCKED
flagvalue- See Also:
- Constant Field Values
-
FLAGS_TOGGLENOVIEW
public static final int FLAGS_TOGGLENOVIEW
flagvalue- See Also:
- Constant Field Values
-
FLAGS_LOCKEDCONTENTS
public static final int FLAGS_LOCKEDCONTENTS
flagvalue PDF 1.7- See Also:
- Constant Field Values
-
APPEARANCE_NORMAL
public static final PdfName APPEARANCE_NORMAL
appearance attributename
-
APPEARANCE_ROLLOVER
public static final PdfName APPEARANCE_ROLLOVER
appearance attributename
-
APPEARANCE_DOWN
public static final PdfName APPEARANCE_DOWN
appearance attributename
-
AA_ENTER
public static final PdfName AA_ENTER
attributevalue
-
AA_EXIT
public static final PdfName AA_EXIT
attributevalue
-
AA_DOWN
public static final PdfName AA_DOWN
attributevalue
-
AA_UP
public static final PdfName AA_UP
attributevalue
-
AA_FOCUS
public static final PdfName AA_FOCUS
attributevalue
-
AA_BLUR
public static final PdfName AA_BLUR
attributevalue
-
AA_JS_KEY
public static final PdfName AA_JS_KEY
attributevalue
-
AA_JS_FORMAT
public static final PdfName AA_JS_FORMAT
attributevalue
-
AA_JS_CHANGE
public static final PdfName AA_JS_CHANGE
attributevalue
-
AA_JS_OTHER_CHANGE
public static final PdfName AA_JS_OTHER_CHANGE
attributevalue
-
MARKUP_HIGHLIGHT
public static final int MARKUP_HIGHLIGHT
attributevalue- See Also:
- Constant Field Values
-
MARKUP_UNDERLINE
public static final int MARKUP_UNDERLINE
attributevalue- See Also:
- Constant Field Values
-
MARKUP_STRIKEOUT
public static final int MARKUP_STRIKEOUT
attributevalue- See Also:
- Constant Field Values
-
MARKUP_SQUIGGLY
public static final int MARKUP_SQUIGGLY
attributevalue- Since:
- 2.1.3
- See Also:
- Constant Field Values
-
writer
protected PdfWriter writer
-
reference
protected PdfIndirectReference reference
Reference to this annotation.- Since:
- 2.1.6; was removed in 2.1.5, but restored in 2.1.6
-
templates
protected java.util.HashSet<PdfTemplate> templates
-
form
protected boolean form
-
annotation
protected boolean annotation
-
used
protected boolean used
Holds value of property used.
-
placeInPage
private int placeInPage
Holds value of property placeInPage.
-
role
protected PdfName role
-
id
private AccessibleElementId id
-
-
Method Detail
-
createScreen
public static PdfAnnotation createScreen(PdfWriter writer, Rectangle rect, java.lang.String clipTitle, PdfFileSpecification fs, java.lang.String mimeType, boolean playOnDisplay) throws java.io.IOException
Creates a screen PdfAnnotation- Parameters:
writer
-rect
-clipTitle
-fs
-mimeType
-playOnDisplay
-- Returns:
- a screen PdfAnnotation
- Throws:
java.io.IOException
-
getIndirectReference
public PdfIndirectReference getIndirectReference()
Returns an indirect reference to the annotation- Returns:
- the indirect reference
-
createText
public static PdfAnnotation createText(PdfWriter writer, Rectangle rect, java.lang.String title, java.lang.String contents, boolean open, java.lang.String icon)
- Parameters:
writer
-rect
-title
-contents
-open
-icon
-- Returns:
- a PdfAnnotation
-
createLink
protected static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight)
Creates a link.- Parameters:
writer
-rect
-highlight
-- Returns:
- A PdfAnnotation
-
createLink
public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, PdfAction action)
Creates an Annotation with an Action.- Parameters:
writer
-rect
-highlight
-action
-- Returns:
- A PdfAnnotation
-
createLink
public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, java.lang.String namedDestination)
Creates an Annotation with an local destination.- Parameters:
writer
-rect
-highlight
-namedDestination
-- Returns:
- A PdfAnnotation
-
createLink
public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, int page, PdfDestination dest)
Creates an Annotation with a PdfDestination.- Parameters:
writer
-rect
-highlight
-page
-dest
-- Returns:
- A PdfAnnotation
-
createFreeText
public static PdfAnnotation createFreeText(PdfWriter writer, Rectangle rect, java.lang.String contents, PdfContentByte defaultAppearance)
Add some free text to the document.- Parameters:
writer
-rect
-contents
-defaultAppearance
-- Returns:
- A PdfAnnotation
-
createLine
public static PdfAnnotation createLine(PdfWriter writer, Rectangle rect, java.lang.String contents, float x1, float y1, float x2, float y2)
Adds a line to the document. Move over the line and a tooltip is shown.- Parameters:
writer
-rect
-contents
-x1
-y1
-x2
-y2
-- Returns:
- A PdfAnnotation
-
createSquareCircle
public static PdfAnnotation createSquareCircle(PdfWriter writer, Rectangle rect, java.lang.String contents, boolean square)
Adds a circle or a square that shows a tooltip when you pass over it.- Parameters:
writer
-rect
-contents
- The tooltipsquare
- true if you want a square, false if you want a circle- Returns:
- A PdfAnnotation
-
createMarkup
public static PdfAnnotation createMarkup(PdfWriter writer, Rectangle rect, java.lang.String contents, int type, float[] quadPoints)
-
createStamp
public static PdfAnnotation createStamp(PdfWriter writer, Rectangle rect, java.lang.String contents, java.lang.String name)
Adds a Stamp to your document. Move over the stamp and a tooltip is shown- Parameters:
writer
-rect
-contents
-name
-- Returns:
- A PdfAnnotation
-
createInk
public static PdfAnnotation createInk(PdfWriter writer, Rectangle rect, java.lang.String contents, float[][] inkList)
-
createFileAttachment
public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, java.lang.String contents, byte[] fileStore, java.lang.String file, java.lang.String fileDisplay) throws java.io.IOException
Creates a file attachment annotation.- Parameters:
writer
- thePdfWriter
rect
- the dimensions in the page of the annotationcontents
- the file descriptionfileStore
- an array with the file. If it'snull
the file will be read from the diskfile
- the path to the file. It will only be used iffileStore
is notnull
fileDisplay
- the actual file name stored in the pdf- Returns:
- the annotation
- Throws:
java.io.IOException
- on error
-
createFileAttachment
public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, java.lang.String contents, PdfFileSpecification fs) throws java.io.IOException
Creates a file attachment annotation- Parameters:
writer
-rect
-contents
-fs
-- Returns:
- the annotation
- Throws:
java.io.IOException
-
createPopup
public static PdfAnnotation createPopup(PdfWriter writer, Rectangle rect, java.lang.String contents, boolean open)
Adds a popup to your document.- Parameters:
writer
-rect
-contents
-open
-- Returns:
- A PdfAnnotation
-
createPolygonPolyline
public static PdfAnnotation createPolygonPolyline(PdfWriter writer, Rectangle rect, java.lang.String contents, boolean polygon, PdfArray vertices)
Creates a polygon or -line annotation- Parameters:
writer
- the PdfWriterrect
- the annotation positioncontents
- the textual content of the annotationpolygon
- if true, the we're creating a polygon annotation, if false, a polylinevertices
- an array with the vertices of the polygon or -line- Since:
- 5.0.2
-
setDefaultAppearanceString
public void setDefaultAppearanceString(PdfContentByte cb)
-
setFlags
public void setFlags(int flags)
-
setBorder
public void setBorder(PdfBorderArray border)
-
setBorderStyle
public void setBorderStyle(PdfBorderDictionary border)
-
setHighlighting
public void setHighlighting(PdfName highlight)
Sets the annotation's highlighting mode. The values can beHIGHLIGHT_NONE
,HIGHLIGHT_INVERT
,HIGHLIGHT_OUTLINE
andHIGHLIGHT_PUSH
;- Parameters:
highlight
- the annotation's highlighting mode
-
setAppearance
public void setAppearance(PdfName ap, PdfTemplate template)
-
setAppearance
public void setAppearance(PdfName ap, java.lang.String state, PdfTemplate template)
-
setAppearanceState
public void setAppearanceState(java.lang.String state)
-
setColor
public void setColor(BaseColor color)
-
setTitle
public void setTitle(java.lang.String title)
-
setPopup
public void setPopup(PdfAnnotation popup)
-
setAction
public void setAction(PdfAction action)
-
isUsed
public boolean isUsed()
Getter for property used.- Returns:
- Value of property used.
-
setUsed
public void setUsed()
Setter for property used.
-
getTemplates
public java.util.HashSet<PdfTemplate> getTemplates()
-
isForm
public boolean isForm()
Getter for property form.- Returns:
- Value of property form.
-
isAnnotation
public boolean isAnnotation()
Getter for property annotation.- Returns:
- Value of property annotation.
-
setPage
public void setPage(int page)
-
setPage
public void setPage()
-
getPlaceInPage
public int getPlaceInPage()
Getter for property placeInPage.- Returns:
- Value of property placeInPage.
-
setPlaceInPage
public void setPlaceInPage(int placeInPage)
Places the annotation in a specified page that must be greater or equal to the current one. WithPdfStamper
the page can be any. The first page is 1.- Parameters:
placeInPage
- New value of property placeInPage.
-
setRotate
public void setRotate(int v)
-
getMK
PdfDictionary getMK()
-
setMKRotation
public void setMKRotation(int rotation)
-
setMKBorderColor
public void setMKBorderColor(BaseColor color)
-
setMKBackgroundColor
public void setMKBackgroundColor(BaseColor color)
-
setMKNormalCaption
public void setMKNormalCaption(java.lang.String caption)
-
setMKRolloverCaption
public void setMKRolloverCaption(java.lang.String caption)
-
setMKAlternateCaption
public void setMKAlternateCaption(java.lang.String caption)
-
setMKNormalIcon
public void setMKNormalIcon(PdfTemplate template)
-
setMKRolloverIcon
public void setMKRolloverIcon(PdfTemplate template)
-
setMKAlternateIcon
public void setMKAlternateIcon(PdfTemplate template)
-
setMKIconFit
public void setMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, boolean fitInBounds)
-
setMKTextPosition
public void setMKTextPosition(int tp)
-
setLayer
public void setLayer(PdfOCG layer)
Sets the layer this annotation belongs to.- Parameters:
layer
- the layer this annotation belongs to
-
setName
public void setName(java.lang.String name)
Sets the name of the annotation. With this name the annotation can be identified among all the annotations on a page (it has to be unique).
-
applyCTM
public void applyCTM(AffineTransform ctm)
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Description copied from class:PdfDictionary
Writes the PDF representation of thisPdfDictionary
as an array ofbyte
to the givenOutputStream
.- Overrides:
toPdf
in classPdfDictionary
- Parameters:
writer
- for backwards compatibilityos
- theOutputStream
to write the bytes to.- Throws:
java.io.IOException
-
getAccessibleAttribute
public PdfObject getAccessibleAttribute(PdfName key)
Description copied from interface:IAccessibleElement
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
getAccessibleAttribute
in interfaceIAccessibleElement
- Returns:
-
setAccessibleAttribute
public void setAccessibleAttribute(PdfName key, PdfObject value)
Description copied from interface:IAccessibleElement
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
setAccessibleAttribute
in interfaceIAccessibleElement
-
getAccessibleAttributes
public java.util.HashMap<PdfName,PdfObject> getAccessibleAttributes()
Description copied from interface:IAccessibleElement
Gets all the properties of accessible element.- Specified by:
getAccessibleAttributes
in interfaceIAccessibleElement
- Returns:
-
getRole
public PdfName getRole()
Description copied from interface:IAccessibleElement
Gets the role of the accessible element.- Specified by:
getRole
in interfaceIAccessibleElement
- Returns:
-
setRole
public void setRole(PdfName role)
Description copied from interface:IAccessibleElement
Sets the role of the accessiblee element. Set role tonull
if you don't want to tag this element. Note that all child elements won't also be tagged.- Specified by:
setRole
in interfaceIAccessibleElement
-
getId
public AccessibleElementId getId()
- Specified by:
getId
in interfaceIAccessibleElement
-
setId
public void setId(AccessibleElementId id)
- Specified by:
setId
in interfaceIAccessibleElement
-
isInline
public boolean isInline()
- Specified by:
isInline
in interfaceIAccessibleElement
-
-