Freeform rotation for PDF annotations

Line, Polygon, Polyline, Freehand, Ellipse, Rectangle, Stamp, FreeText annotations show a rotation control when selected. This control handle lets the user rotate the annotation with a full range (360 degrees).

Apryse Docs Image

Rotating annotations programmatically

To rotate annotations programmatically, supported annotations have a rotate function that takes an angle to rotate by:

JavaScript (v8.0+)

1const { annotationManager, Annotations } = instance.Core;
2annotationManager.getAnnotationsList().forEach((annotation) => {
3 if (annotation instanceof Annotations.RectangleAnnotation) {
4 annotation.rotate(45);
5 }
6});

Disabling freeform rotation

By default, freeform rotation is enabled for all Line, Polyline, Polygon or Freehand annotations. In order to disable it, the following can be done:

1const annotManager = instance.Core.annotationManager;
2annotManager.setRotationOptions({
3 isEnabled: false,
4});

Using the setRotationOptions API, then you can disable rotation completely. If you would like to disable free form rotation on certain annotations, then the following can be used instead:

1Webviewer(...)
2 .then(instance => {
3 const { annotationManager } = instance.Core;
4
5 annotationManager.addEventListener('annotationChanged', (annotations, action) => {
6 if (action === 'add') {
7 annotations.forEach((annotation) => {
8 annotation.disableRotationControl();
9 });
10 }
11 });
12 });

Vice-versa, to enable rotation controls, you would use the enableRotationControl API.

Configuring freeform rotation options

If you would like to configure the rotation type and rotation step sizes, that can be done with the same setRotationOptions API.

JavaScript (v8.0+)

1const annotManager = instance.Core.annotationManager;
2annotManager.setRotationOptions({
3 isEnabled: true,
4 defaultRotationType: Core.AnnotationManager.RotationTypes.SNAP_ROTATION,
5 hotkeyTogglesRotationType: false,
6 snapAngleStepSizeInDegrees: 60,
7});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales