Namespace: Annotations

Annotations

The namespace for anything to do with PDF annotations.

Classes

Annotation
Border
BoxControlHandle
BoxSelectionModel
ButtonWidgetAnnotation
CalloutControlHandle
CalloutSelectionModel
CanvasHelper
CaretAnnotation
CheckButtonWidgetAnnotation
ChoiceWidgetAnnotation
Color
ControlHandle
CustomAnnotation
DatePickerWidgetAnnotation
EllipseAnnotation
FileAttachmentAnnotation
Font
Forms
FreeHandAnnotation
FreeTextAnnotation
FreeTextSelectionModel
HTMLAnnotation
IPathAnnotation
LineAnnotation
LineControlHandle
LineSelectionModel
Link
ListWidgetAnnotation
MarkupAnnotation
PathControlHandle
PathSelectionModel
PolygonAnnotation
PolygonControlHandle
PolygonSelectionModel
PolylineAnnotation
PopupAnnotation
RadioButtonWidgetAnnotation
RectangleAnnotation
RedactionAnnotation
RedactionSelectionModel
RotationControlHandle
SelectionModel
SignatureWidgetAnnotation
StampAnnotation
StickyAnnotation
TextHighlightAnnotation
TextMarkupAnnotation
TextRedactAnnotation
TextSelectionModel
TextSquigglyAnnotation
TextStrikeoutAnnotation
TextUnderlineAnnotation
TextWidgetAnnotation
WidgetAnnotation
WidgetFlags

Namespaces

SelectionAlgorithm

Members


<static> CustomDrawOptions

Custom drawing options.
Properties:
Name Type Argument Description
generateAppearance boolean <optional>
Whether to generate a custom appearance. Defaults to true
canvasMultiplier number <optional>
The quality value of the generated custom appearance. The higher the value, the more memory is required. By default, this will use the canvas multiplier value set in WebViewer

<static> LineEndType

An enum representing different line end types that are available for line annotations
Properties:
Name Type Description
NONE string No line endings
OPEN_ARROW string an arrow that points outward
R_OPEN_ARROW string an arrow that points inward
CLOSED_ARROW string a triangle that points outward
R_CLOSED_ARROW string a triangle that points inward
BUTT string a vertical line
SQUARE string a square
DIAMOND string a diamond
CIRCLE string a circle
SLASH string a slash

<static> XfdfUtils

Methods


<static> restoreDeserialize(annotationClass)

Restores the deserialize function back to the default.
Parameters:
Name Type Description
annotationClass Annotations.Annotation The class (constructor) of the annotation

<static> restoreDraw(annotationClass)

Restores the draw function back to the default.
Parameters:
Name Type Description
annotationClass Annotations.Annotation The class (constructor) of the annotation

<static> restoreSerialize(annotationClass)

Restores the serialize function back to the default.
Parameters:
Name Type Description
annotationClass Annotations.Annotation The class (constructor) of the annotation

<static> setCustomDeserializeHandler(annotationClass, deserializeHandler)

Changes how an annotation type is deserialized within WebViewer. If your custom property/attribute is stored in the CustomData, please consider using getCustomData instead.
Parameters:
Name Type Description
annotationClass Annotations.Annotation The class (constructor) of the annotation
deserializeHandler Annotations.CustomAnnotationDeserializeHandler A handler function that will deserialize the annotation
Example
Annotations.setCustomDeserializeHandler(Annotations.RectangleAnnotation, function(element, pageMatrix, options) {
  const annot = options.annotation;
  options.originalDeserialize(element, pageMatrix)
  if (annot.Width > 100) {
    annot.myProperty = element.getAttribute('myAttr');
  }
});

<static> setCustomDrawHandler(annotationClass, drawHandler [, options])

Changes how an annotation type is drawn within WebViewer. By default, this will also generate an appearance for the annotation when the document is downloaded, so it will appear the same in other viewers. Please note that changes to the annotation may cause the appearance to be discarded, reverting it back to normal. The appearance set by addCustomAppearance will take priority.
Parameters:
Name Type Argument Description
annotationClass Annotations.Annotation The class (constructor) of the annotation
drawHandler Annotations.CustomAnnotationDrawHandler A handler function that will draw the annotation
options Annotations.CustomDrawOptions <optional>
Optional options
Properties
Name Type Argument Description
generateAppearance boolean <optional>
Whether to generate a custom appearance (unavailable for pdf.js). Defaults to true
canvasMultiplier number <optional>
The quality value of the generated custom appearance. The higher the value, the more memory is required. By default, this will use the canvas multiplier value set in WebViewer
Example
Annotations.setCustomDrawHandler(Annotations.RectangleAnnotation, function(ctx, pageMatrix) {
  const annot = options.annotation;
  annot.setStyles(ctx, pageMatrix);
  ctx.fillRect(annot.X, annot.Y, annot.Width, annot.Height);
});

<static> setCustomSerializeHandler(annotationClass, serializeHandler)

Changes how an annotation type is serialized within WebViewer. Note that custom attributes will not be persisted in the downloaded PDF and are only useful if you're saving the XFDF separately from the PDF. If you are looking to save your custom property/attribute, please consider using setCustomData which will be persisted.
Parameters:
Name Type Description
annotationClass Annotations.Annotation The class (constructor) of the annotation
serializeHandler Annotations.CustomAnnotationSerializeHandler A handler function that will serialize the annotation
Example
Annotations.setCustomSerializeHandler(Annotations.RectangleAnnotation, function(element, pageMatrix, options) {
  const annot = options.annotation;
  options.originalSerialize(element, pageMatrix)
  if (annot.Width > 100) {
    element.setAttribute('myAttr', 1);
  }
  return element;
});

Type Definitions


CustomAnnotationDeserializeHandler(element, pageMatrix, options)

Callback that gets passed to `deserializeHandler` in setCustomDeserializeHandler. The signature is similar to deserialize except with an additional options parameter.
Parameters:
Name Type Description
element Element An xml element representing the annotation
pageMatrix object The page matrix used to convert PDF coordinates to viewer coordinates
options object Additional options and parameters
Properties
Name Type Description
annotation Annotations.Annotation The annotation being deserialized
originalDeserialize function The original deserialize function of this annotation
Example
Annotations.setCustomDeserializeHandler(Annotations.RectangleAnnotation, function(element, pageMatrix, options) {
  const annot = options.annotation;
  options.originalDeserialize(element, pageMatrix)
  if (annot.Width > 100) {
    annot.myProperty = element.getAttribute('myAttr');
    annot.myOtherId = element.getAttribute('myId');
  }
});

CustomAnnotationDrawHandler(ctx, pageMatrix, rotation, options)

Callback that gets passed to `drawHandler` in setCustomDrawHandler. The signature is similar to draw except with an additional options parameter.
Parameters:
Name Type Description
ctx CanvasRenderingContext2D A canvas context
pageMatrix object The transformation matrix for the page that the annotation is on
rotation object Certain annotations, such as sticky notes, get rotation as a third parameter. Default: undefined
options object Additional options and parameters
Properties
Name Type Description
annotation Annotations.Annotation The annotation being drawn
originalDraw function The original draw function of this annotation
Example
Annotations.setCustomDrawHandler(Annotations.RectangleAnnotation, function(ctx, pageMatrix, rotation, options) {
  const annot = options.annotation;
  if (annot.Width > 100) {
    annot.setStyles(ctx, pageMatrix);
    ctx.fillRect(annot.X, annot.Y, annot.Width, annot.Height);
  } else {
    options.originalDraw(ctx, pageMatrix);
  }
});

CustomAnnotationSerializeHandler(element, pageMatrix, options)

Callback that gets passed to `serializeHandler` in setCustomSerializeHandler. The signature is similar to serialize except with an additional options parameter.
Parameters:
Name Type Description
element Element An xml element representing the annotation
pageMatrix object The page matrix used to convert PDF coordinates to viewer coordinates
options object Additional options and parameters
Properties
Name Type Description
annotation Annotations.Annotation The annotation being serialized
originalSerialize function The original serialize function of this annotation
Returns:
The resulting xml element representing the annotation
Type
Element
Example
Annotations.setCustomSerializeHandler(Annotations.RectangleAnnotation, function(element, pageMatrix, options) {
  const annot = options.annotation;
  options.originalSerialize(element, pageMatrix)
  if (annot.Width > 100) {
    element.setAttribute('myAttr', 1);
    element.setAttribute('myId', annot.Id);
  }
  return element;
});