The annotation to rotate
Rotation angle in degrees
OptionalcontentSize: NutrientViewer.Geometry.SizeSize of the annotation's content for annotations rotated a in multiple of 45 degrees.
Rotate a text annotation to 110 degrees.
const annotation = new NutrientViewer.Annotations.TextAnnotation({
text: `This is a test text for rotating
an annotation to 110 degrees.`,
boundingBox: new NutrientViewer.Geometry.Rect({
x: 300,
y: 300,
width: 246,
height: 44
}),
fontSize: 18,
font: "Helvetica"
});
const rotatedAnnotation = NutrientViewer.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 NutrientViewer.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 NutrientViewer.Annotations.TextAnnotation({
text: `This is a test text for a 45
degree rotated text annotation.`,
rotation: 45,
boundingBox: new NutrientViewer.Geometry.Rect({
x: 300,
y: 300,
width: 348,
height: 348
}),
fontSize: 18,
font: "Helvetica"
});
const rotated60Annotation = NutrientViewer.Annotations.rotate(
rotated45Annotation,
60,
new NutrientViewer.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.
Annotation free rotate helper. Rotates a AnnotationsUnion by the provided angle in degrees, counter-clockwise. It only works with free rotatable annotations, such as NutrientViewer.Annotations.TextAnnotation, NutrientViewer.Annotations.ImageAnnotation and NutrientViewer.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.