Namespace: Annotations

PSPDFKit.Annotations

Annotation API (with all available annotation types). All classes are based on Immutable.Record.

Classes

Methods




Methods

(static) fromSerializableObject(annotation) → {AnnotationsUnion}

Annotation deserializer. Converts an annotation object to a AnnotationsUnion.

Parameters:
Name Type Description
annotation object

Serialized Annotation

Returns:
Type
AnnotationsUnion

Annotation free rotate helper. Rotates a AnnotationsUnion by the provided angle in degrees, counter-clockwise. It only works with free rotatable annotations, such as PSPDFKit.Annotations.TextAnnotation, PSPDFKit.Annotations.ImageAnnotation and PSPDFKit.Annotations.StampAnnotation.

In order to rotate an annotation it's not enough to just change the rotation property. The annotation's bounding box need to be resized and repositioned as well so as to fit the rotated content inside.

This helper facilitates this task by updating both the rotation property and the bounding box.

Parameters:
Name Type Attributes Description
PSPDFKit.Annotations.TextAnnotation | PSPDFKit.Annotations.ImageAnnotation | PSPDFKit.Annotations.StampAnnotation
rotation number

Rotation angle in degrees

contentSize PSPDFKit.Geometry.Size <nullable>

Size of the annotation's content for annotations rotated a in multiple of 45 degrees.

Returns:
Type
PSPDFKit.Annotations.TextAnnotation | PSPDFKit.Annotations.ImageAnnotation | PSPDFKit.Annotations.StampAnnotation
Examples

Rotate a text annotation to 110 degrees.

const annotation = new PSPDFKit.Annotations.TextAnnotation({
  text: `This is a test text for rotating
an annotation to 110 degrees.`,
  boundingBox: new PSPDFKit.Geometry.Rect({
    x: 300,
    y: 300,
    width: 246,
    height: 44
  }),
  fontSize: 18,
  font: "Helvetica"
});
const rotatedAnnotation = PSPDFKit.Annotations.rotate(
  annotation,
  110
);
instance.create(rotatedAnnotation.set('pageIndex', 0));

There is an edge case where the original annotation is already rotated by a multiple of 45 degrees. In this case
it's not possible to figure out the dimensions of the content, which will default to a square that fits in the bounding box.
In order to use the correct content dimensions, you can optionally provide a PSPDFKit.Geometry.Size object
that specifies the content's width and height, which should fit in the annotation's bounding box when using the
annotation rotation.

For cases when the original annotation is rotated by any other angle, the content dimensions are calculated automatically,
but you can still provide this object if the annotation's bounding box does not correctly bound the content, so as to obtain
an annotation with a correctly bounding box as a result.

Rotate a 45 degree rotated annotation to 60 degrees.

const rotated45Annotation = new PSPDFKit.Annotations.TextAnnotation({
  text: `This is a test text for a 45
degree rotated text annotation.`,
  rotation: 45,
  boundingBox: new PSPDFKit.Geometry.Rect({
    x: 300,
    y: 300,
    width: 348,
    height: 348
  }),
  fontSize: 18,
  font: "Helvetica"
});
const rotated60Annotation = PSPDFKit.Annotations.rotate(
  rotated45Annotation,
  60,
  new PSPDFKit.Geometry.Size({ width: 246, height: 44 })
);
instance.create(rotated60Annotation.set('pageIndex', 0));

This helper does not check if the resulting rotated annotation overflows the page limits.

(static) toSerializableObject() → {object}

Annotation serializer. Converts one of the supported PSPDFKit.Annotations to InstantJSON compliant objects.

Parameters:
Type Description
AnnotationsUnion
Returns:
Type
object