PDFAnnotation
¶
PDF Annotations belong to a specific PDFPage
and may be created/changed/removed. Because annotation appearances may change (for several reasons) it is possible to scan through the annotations on a page and query them to see whether a re-render is necessary. Finally redaction annotations can be applied to a PDFPage
, destructively removing content from the page.
To get the annotations on a page see: PDFPage getAnnotations(), to create an annotation see: PDFPage createAnnotation().
Instance methods
- getBounds()¶
Returns a rectangle containing the location and dimension of the annotation.
- Returns:
[ulx,uly,lrx,lry]
Rectangle.
EXAMPLE
var bounds = annotation.getBounds();
- run(device, transform)¶
Calls the device functions to draw the annotation.
- Arguments:
device –
Device
.transform –
[a,b,c,d,e,f]
. The transform matrix.
EXAMPLE
annotation.run(device, mupdf.Matrix.identity);
- toPixmap(transform, colorspace, alpha)¶
Render the annotation into a
Pixmap
, using the transform and colorspace.- Arguments:
transform –
[a,b,c,d,e,f]
. The transform matrix.colorspace –
ColorSpace
.alpha –
Boolean
.
- Returns:
Pixmap
.
EXAMPLE
var pixmap = annotation.toPixmap(mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, true);
- toDisplayList()¶
Record the contents of the annotation into a
DisplayList
.- Returns:
DisplayList
.
EXAMPLE
var displayList = annotation.toDisplayList();
- getObject()¶
Get the underlying
PDFObject
for an annotation.- Returns:
PDFObject
.
EXAMPLE
var obj = annotation.getObject();
- process(processor)¶
mutool only
Run through the annotation appearance stream and call methods on the supplied PDF processor.
- Arguments:
processor – User defined function.
EXAMPLE
annotation.process(processor);
- setAppearance(appearance, state, transform, displayList)¶
Set the annotation appearance stream for the given appearance. The desired appearance is given as a transform along with a display list.
- Arguments:
appearance –
String
Appearance stream (“N”, “R” or “D”).state –
String
The annotation state to set the appearance for or null for the current state. Only widget annotations of pushbutton, check box, or radio button type have states, which are “Off” or “Yes”. For other types of annotations pass null.transform –
[a,b,c,d,e,f]
. The transform matrix.displayList –
DisplayList
.
EXAMPLE
annotation.setAppearance("N", null, mupdf.Matrix.identity, displayList);
- setAppearance(appearance, state, transform, bbox, resources, contents)¶
Set the annotation appearance stream for the given appearance. The desired appearance is given as a transform along with a bounding box, a PDF dictionary of resources and a content stream.
- Arguments:
appearance –
String
Appearance stream (“N”, “R” or “D”).state –
String
The annotation state to set the appearance for or null for the current state. Only widget annotations of pushbutton, check box, or radio button type have states, which are “Off” or “Yes”. For other types of annotations pass null.transform –
[a,b,c,d,e,f]
. The transform matrix.bbox –
[ulx,uly,lrx,lry]
Rectangle.resources – Resources object.
contents – Contents string.
EXAMPLE
annotation.setAppearance("N", null, mupdf.Matrix.identity, [0,0,100,100], resources, contents);
Appearance stream values
Value |
Description |
---|---|
N |
normal appearance |
R |
roll-over appearance |
D |
down (pressed) appearance |
- update()¶
Update the appearance stream to account for changes in the annotation.
EXAMPLE
annotation.update();
- getHot()¶
mutool only
Get the annotation as being hot, i.e. that the pointer is hovering over the annotation.
- Returns:
Boolean
.
EXAMPLE
annotation.getHot();
- setHot(hot)¶
mutool only
Set the annotation as being hot, i.e. that the pointer is hovering over the annotation.
- Arguments:
hot –
Boolean
.
EXAMPLE
annotation.setHot(true);
- getHiddenForEditing()¶
mutool only
Get a special annotation hidden flag for editing. This flag prevents the annotation from being rendered.
- Returns:
Boolean
.
EXAMPLE
var hidden = annotation.getHiddenForEditing();
- setHiddenForEditing(hidden)¶
mutool only
Set a special annotation hidden flag for editing. This flag prevents the annotation from being rendered.
- Arguments:
hidden –
Boolean
.
EXAMPLE
annotation.setHiddenForEditing(true);
- getType()¶
Return the annotation type.
- Returns:
String
Annotation type.
EXAMPLE
var type = annotation.getType();
- getFlags()¶
Get the annotation flags.
- Returns:
Integer
representaton of a bit-field of flags specified below.
EXAMPLE
var flags = annotation.getFlags();
- setFlags(flags)¶
Set the annotation flags.
- Arguments:
flags –
Integer
representaton of a bit-field of flags specified below.
EXAMPLE
annotation.setFlags(8); // Clears all other flags and sets NoZoom.
Annotation flags
Bit position |
Name |
---|---|
|
Invisible |
|
Hidden |
|
|
|
NoZoom |
|
NoRotate |
|
NoView |
|
ReadOnly |
|
Locked |
|
ToggleNoView |
|
LockedContents |
- getContents()¶
Get the annotation contents.
- Returns:
String
.
EXAMPLE
var contents = annotation.getContents();
- setContents(text)¶
Set the annotation contents.
- Arguments:
text –
String
.
EXAMPLE
annotation.setContents("Hello World");
- getBorder()¶
mutool only
Get the annotation border line width in points.
- Returns:
Float
.
EXAMPLE
var border = annotation.getBorder();
- setBorder(width)¶
mutool only
Set the annotation border line width in points. Use
setBorderWidth()
to avoid removing the border effect.- Arguments:
width –
Float
Border width.
EXAMPLE
annotation.setBorder(1.0);
- getColor()¶
Get the annotation color, represented as an array of 1, 3, or 4 component values.
- Returns:
The color value.
EXAMPLE
var color = annotation.getColor();
- setColor(color)¶
Set the annotation color, represented as an array of 1, 3, or 4 component values.
- Arguments:
color – The color value.
EXAMPLE
annotation.setColor([0,1,0]);
- getOpacity()¶
Get the annotation opacity.
- Returns:
The opacity value.
EXAMPLE
var opacity = annotation.getOpacity();
- setOpacity(opacity)¶
Set the annotation opacity.
- Arguments:
opacity – The opacity value.
EXAMPLE
annotation.setOpacity(0.5);
- getCreationDate()¶
Get the annotation creation date as a JavaScript
Date
object.- Returns:
Date
.
EXAMPLE
var date = annotation.getCreationDate();
- setCreationDate(date)¶
Set the creation date.
- Arguments:
date –
Date
.
EXAMPLE
annotation.setCreationDate(new Date());
- getModificationDate()¶
Get the annotation modification date as a JavaScript
Date
object.- Returns:
Date
.
EXAMPLE
var date = annotation.getModificationDate();
- setModificationDate(date)¶
Set the modification date.
- Arguments:
date –
Date
.
EXAMPLE
annotation.setModificationDate(new Date());
- getQuadding()¶
Get the annotation quadding (justification).
- Returns:
Quadding value,
0
for left-justified,1
for centered,2
for right-justified.
EXAMPLE
var quadding = annotation.getQuadding();
- setQuadding(value)¶
Set the annotation quadding (justification).
- Arguments:
value – Quadding value,
0
for left-justified,1
for centered,2
for right-justified.
EXAMPLE
annotation.setQuadding(1);
- getLanguage()¶
Get the annotation language (or get the inherited document language).
- Returns:
String
.
EXAMPLE
var language = annotation.getLanguage();
- setLanguage(language)¶
Set the annotation language.
- Arguments:
language –
String
.
EXAMPLE
annotation.setLanguage("en");
These properties are only present for some annotation types, so support for them must be checked before use.
- getRect()¶
Get the annotation bounding box.
- Returns:
[ulx,uly,lrx,lry]
Rectangle.
EXAMPLE
var rect = annotation.getRect();
- setRect(rect)¶
Set the annotation bounding box.
- Arguments:
rect –
[ulx,uly,lrx,lry]
Rectangle.
EXAMPLE
annotation.setRect([0,0,100,100]);
- getDefaultAppearance()¶
Get the default text appearance used for free text annotations.
- Returns:
{font:String, size:Integer, color:[r,g,b]}
Returns an object with the key/value pairs.
EXAMPLE
var appearance = annotation.getDefaultAppearance();
Jamie TODO how about describing the DefaultApperance as a separate object similar to the link destination?
- setDefaultAppearance(font, size, color)¶
Set the default text appearance used for free text annotations.
- Arguments:
font –
String
.size –
Integer
.color – The color value.
EXAMPLE
annotation.setDefaultAppearance("Helv", 16, [0,0,0]);
- hasInteriorColor()¶
mutool only
Checks whether the annotation has support for an interior color.
- Returns:
Boolean
.
EXAMPLE
var hasInteriorColor = annotation.hasInteriorColor();
- getInteriorColor()¶
Gets the annotation interior color.
- Returns:
The color value.
EXAMPLE
var interiorColor = annotation.getInteriorColor();
- setInteriorColor(color)¶
Sets the annotation interior color.
- Arguments:
color – The color value.
EXAMPLE
annotation.setInteriorColor([0,1,1]);
- hasAuthor()¶
mutool only
Checks whether the annotation has an author.
- Returns:
Boolean
.
EXAMPLE
var hasAuthor = annotation.hasAuthor();
- getAuthor()¶
Gets the annotation author.
- Returns:
String
.
EXAMPLE
var author = annotation.getAuthor();
- setAuthor(author)¶
Sets the annotation author.
- Arguments:
author –
String
.
EXAMPLE
annotation.setAuthor("Jane Doe");
- hasLineEndingStyles()¶
mutool only
Checks the support for line ending styles.
- Returns:
Boolean
.
EXAMPLE
var hasLineEndingStyles = annotation.hasLineEndingStyles();
- getLineEndingStyles()¶
Gets the line ending styles object.
- Returns:
{start:String, end:String}
Returns an object with the key/value pairs.
EXAMPLE
var lineEndingStyles = annotation.getLineEndingStyles();
- setLineEndingStyles(start, end)¶
Sets the line ending styles object.
- Arguments:
start –
String
.end –
String
.
EXAMPLE
annotation.setLineEndingStyles({start:"Square", end:"OpenArrow"});
Line ending names |
---|
“None” |
“Square” |
“Circle” |
“Diamond” |
“OpenArrow” |
“ClosedArrow” |
“Butt” |
“ROpenArrow” |
“RClosedArrow” |
“Slash” |
- hasIcon()¶
mutool only
Checks the support for annotation icon.
- Returns:
Boolean
.
EXAMPLE
var hasIcon = annotation.hasIcon();
- getIcon()¶
Gets the annotation icon name, either one of the standard icon names, or something custom.
- Returns:
String
.
EXAMPLE
var icon = annotation.getIcon();
- setIcon(name)¶
Sets the annotation icon name, either one of the standard icon names, or something custom. Note that standard icon names can be used to resynthesize the annotation apperance, but custom names cannot.
- Arguments:
name –
String
.
EXAMPLE
annotation.setIcon("Note");
Icon type |
Icon name |
---|---|
File attachment |
“Graph” |
“PaperClip” |
|
“PushPin” |
|
“Tag” |
|
Sound |
“Mic” |
“Speaker” |
|
Stamp |
“Approved” |
“AsIs” |
|
“Confidential” |
|
“Departmental” |
|
“Draft” |
|
“Experimental” |
|
“Expired” |
|
“Final” |
|
“ForComment” |
|
“ForPublicRelease” |
|
“NotApproved” |
|
“NotForPublicRelease” |
|
“Sold” |
|
“TopSecret” |
|
Text |
“Comment” |
“Help” |
|
“Insert” |
|
“Key” |
|
“NewParagraph” |
|
“Note” |
|
“Paragraph” |
- hasLine()¶
mutool only
Checks the support for annotation line.
- Returns:
Boolean
.
EXAMPLE
var hasLine = annotation.hasLine();
- getLine()¶
Get line end points, represented by an array of two points, each represented as an
[x, y]
array.- Returns:
[[x,y],...]
.
EXAMPLE
var line = annotation.getLine();
- setLine(endpoints)¶
Set the two line end points, represented by an array of two points, each represented as an
[x, y]
array.- Arguments:
endpoint1 –
[x,y]
.endpoint2 –
[x,y]
.
EXAMPLE
annotation.setLine([100,100], [150, 175]);
- hasOpen()¶
mutool only
Checks the support for annotation open state.
- Returns:
Boolean
.
EXAMPLE
var hasOpen = annotation.hasOpen();
- getIsOpen()¶
Get annotation open state.
- Returns:
Boolean
.
EXAMPLE
var isOpen = annotation.getIsOpen();
- setIsOpen(state)¶
mutool only
Set annotation open state.
- Arguments:
state –
Boolean
.
EXAMPLE
annotation.setIsOpen(true);
Note
“Open” refers to whether the annotation is display in an open state when the page is loaded. A Text Note annotation is considered “Open” if the user has clicked on it to view its contents.
- hasFilespec()¶
mutool only
Checks support for the annotation file specification.
- Returns:
Boolean
.
EXAMPLE
var hasFileSpec = annotation.hasFilespec();
- getFilespec()¶
mutool only
Gets the file specification object.
- Returns:
Object
File Specification Object.
EXAMPLE
var fileSpec = annotation.getFilespec(true);
- setFilespec(fileSpecObject)¶
mutool only
Sets the file specification object.
- Arguments:
fileSpecObject –
Object
File Specification object.
EXAMPLE
annotation.setFilespec({filename:"my_file.pdf", mimetype:"application/pdf", size:1000, creationDate:date, modificationDate:date});
The border drawn around some annotations can be controlled by:
- hasBorder()¶
mutool only
Check support for the annotation border style.
- Returns:
Boolean
.
EXAMPLE
var hasBorder = annotation.hasBorder();
- getBorderStyle()¶
Get the annotation border style, either of “Solid” or “Dashed”.
- Returns:
String
.
EXAMPLE
var borderStyle = annotation.getBorderStyle();
- setBorderStyle(style)¶
Set the annotation border style, either of “Solid” or “Dashed”.
- Arg:
String
.
EXAMPLE
annotation.setBorderStyle("Dashed");
- getBorderWidth()¶
Get the border width in points.
- Returns:
Float
.
EXAMPLE
var w = annotation.getBorderWidth();
- setBorderWidth(width)¶
Set the border width in points. Retain any existing border effects.
- Arguments:
width –
Float
.
EXAMPLE
annotation.setBorderWidth(1.5);
- getBorderDashCount()¶
Returns the number of items in the border dash pattern.
- Returns:
Integer
.
EXAMPLE
var dashCount = annotation.getBorderDashCount();
- getBorderDashItem(i)¶
Returns the length of dash pattern item
i
.- Arguments:
i –
Integer
Item index.
- Returns:
Float
.
EXAMPLE
var length = annotation.getBorderDashItem(0);
- setBorderDashPattern(dashPattern)¶
Set the annotation border dash pattern to the given array of dash item lengths. The supplied array represents the respective line stroke and gap lengths, e.g.
[1,1]
sets a small dash and small gap,[2,1,4,1]
would set a medium dash, a small gap, a longer dash and then another small gap.- Arguments:
dashpattern – [Float, Float, ….].
EXAMPLE
annotation.setBorderDashPattern([2.0, 1.0, 4.0, 1.0]);
- clearBorderDash()¶
Clear the entire border dash pattern for an annotation.
EXAMPLE
annotation.clearBorderDash();
- addBorderDashItem(length)¶
Append an item (of the given length) to the end of the border dash pattern.
- Arguments:
length –
Float
.
EXAMPLE
annotation.addBorderDashItem(10.0);
Annotations that have a border effect allows the effect to be controlled by:
- hasBorderEffect()¶
mutool only
Check support for annotation border effect.
- Returns:
Boolean
.
EXAMPLE
var hasEffect = annotation.hasBorderEffect();
- getBorderEffect()¶
Get the annotation border effect, either of “None” or “Cloudy”.
- Returns:
String
.
EXAMPLE
var effect = annotation.getBorderEffect();
- setBorderEffect(effect)¶
Set the annotation border effect, either of “None” or “Cloudy”.
- Arg:
String
.
EXAMPLE
annotation.setBorderEffect("None");
- getBorderEffectIntensity()¶
Get the annotation border effect intensity.
- Returns:
Float
.
EXAMPLE
var intensity = annotation.getBorderEffectIntensity();
- setBorderEffectIntensity(intensity)¶
Set the annotation border effect intensity. Recommended values are between
0
and2
inclusive.- Arg:
Float
.
EXAMPLE
annotation.setBorderEffectIntensity(1.5);
Ink annotations consist of a number of strokes, each consisting of a sequence of vertices between which a smooth line will be drawn. These can be controlled by:
- hasInkList()¶
Check support for the annotation ink list.
- Returns:
Boolean
.
EXAMPLE
var hasInkList = annotation.hasInkList();
- getInkList()¶
Get the annotation ink list, represented as an array of strokes, each an array of points each an array of its X/Y coordinates.
- Returns:
[...]
.
EXAMPLE
var inkList = annotation.getInkList();
- setInkList(inkList)¶
Set the annotation ink list, represented as an array of strokes, each an array of points each an array of its X/Y coordinates.
- Arg:
[...]
.
EXAMPLE
annotation.setInkList([ [ [0,0] ], [ [10,10], [20,20], [30,30] ] ]);
- clearInkList()¶
Clear the list of ink strokes for the annotation.
EXAMPLE
annotation.clearInkList();
- addInkList(stroke)¶
To the list of strokes, append a stroke, represented as an array of vertices each an array of its X/Y coordinates.
- Arguments:
stroke –
[]
.
EXAMPLE
annotation.addInkList( [ [0,0] ], [ [10,10], [20,20], [30,30] ] );
- addInkListStroke()¶
Add a new empty stroke to the ink annotation.
EXAMPLE
annotation.addInkListStroke();
- addInkListStrokeVertex(vertex)¶
Append a vertex to end of the last stroke in the ink annotation. The vertex is an array of its X/Y coordinates.
- Arguments:
vertex –
[...]
.
EXAMPLE
annotation.addInkListStrokeVertex([0,0]);
Text markup and redaction annotations consist of a set of quadadrilaterals controlled by:
- hasQuadPoints()¶
mutool only
Check support for the annotation quadpoints.
- Returns:
Boolean
.
EXAMPLE
var hasQuadPoints = annotation.hasQuadPoints();
- getQuadPoints()¶
Get the annotation quadpoints, describing the areas affected by text markup annotations and link annotations.
- Returns:
[...]
.
EXAMPLE
var quadPoints = annotation.getQuadPoints();
- setQuadPoints(quadPoints)¶
Set the annotation quadpoints, describing the areas affected by text markup annotations and link annotations.
- Arguments:
quadPoints –
[...]
.
EXAMPLE
annotation.setQuadPoints([ [1,2,3,4,5,6,7,8], [1,2,3,4,5,6,7,8], [1,2,3,4,5,6,7,8] ]);
- clearQuadPoints()¶
Clear the list of quad points for the annotation.
EXAMPLE
annotation.clearQuadPoints();
- addQuadPoint(quadpoint)¶
Append a single quad point as an array of 8 elements, where each pair are the X/Y coordinates of a corner of the quad.
- Arguments:
quadpoint –
[]
.
EXAMPLE
annotation.setQuadPoints([1,2,3,4,5,6,7,8]);
Polygon and polyline annotations consist of a sequence of vertices with a straight line between them. Those can be controlled by:
- hasVertices()¶
mutool only
Check support for the annotation vertices.
- Returns:
Boolean
.
EXAMPLE
var hasVertices = annotation.hasVertices();
- getVertices()¶
Get the annotation vertices, represented as an array of vertices each an array of its X/Y coordinates.
- Returns:
[...]
.
EXAMPLE
var vertices = annotation.getVertices();
- setVertices(vertices)¶
Set the annotation vertices, represented as an array of vertices each an array of its X/Y coordinates.
- Arguments:
vertices –
[...]
.
EXAMPLE
annotation.setVertices([ [0,0], [10,10], [20,20] ]);
- clearVertices()¶
Clear the list of vertices for the annotation.
EXAMPLE
annotation.clearVertices();
- addVertex(vertex)¶
mutool only
Append a single vertex as an array of its X/Y coordinates.
- Arguments:
vertex –
[...]
.
EXAMPLE
annotation.addVertex([0,0]);
- applyRedaction(blackBoxes, imageMethod)¶
Applies redaction to the annotation.
- Arguments:
blackBoxes –
Boolean
Whether to use black boxes at each redaction or not.imageMethod –
Integer
.0
for no redactions,1
to redact entire images,2
for redacting just the covered pixels.
Note
Redactions are secure as they remove the affected content completely.
EXAMPLE
annotation.applyRedaction(true, 1);