Annotations
Register to added annotation event
- Object: getARenderJS().getAnnotationJSAPI()
Function Description registerNotifyAnnotationAddedEvent(callback) Register a callback function that will be called when an annotation is added.
/*
* Register to added annotation event
*
* @param {string} documentId - ID of the document
* @param {string} annotation - The json of the added annotation to the document
* @param {boolean} isFromDocumentParsing - True if the added annotation came from parsing of the document
*/
getARenderJS().getAnnotationJSAPI().registerNotifyAnnotationAddedEvent(function(documentId, annotation, isFromDocumentParsing) {
console.log("Annotation added. DocumentId " + documentId + " annotation: " + annotation + " isFromDocumentParsing: " + isFromDocumentParsing);
});
Register to deleted annotation event
- Object: getARenderJS().getAnnotationJSAPI()
Function Description registerNotifyAnnotationDeletedEvent(callback) Register a callback function that will be called when an annotation is deleted.
/*
* Register to deleted annotation event
*
* @param {string} documentId - ID of the document
* @param {string} annotation - The json of the deleted annotation from the document
*/
getARenderJS().getAnnotationJSAPI().registerNotifyAnnotationDeletedEvent(function(documentId, annotation) {
console.log("Annotation deleted. DocumentId " + documentId + " annotation: " + annotation);
});
Register to updated annotation event
- Object: getARenderJS().getAnnotationJSAPI()
Function Description registerNotifyAnnotationUpdatedEvent(callback) Register a callback function that will be called when an annotation is updated.
/*
* Register to updated annotation event
*
* @param {string} documentId - ID of the document
* @param {string} annotation - Updated annotation from the document
*/
getARenderJS().getAnnotationJSAPI().registerNotifyAnnotationUpdatedEvent(function(documentId, annotation) {
console.log("Annotation updated. DocumentId " + documentId + " annotation: " + annotation);
});
Register to Page rotated event
- Object: getARenderJS().getRotateJSAPI()
Function Description registerNotifyPageRotatedEvent(callback) Register a callback function that will be called when a page is rotated
/*
* Subscribe a function to the page rotated event
*
* @param {string} documentId - ID of the document
* @param {integer} pageNumber - The page rotated
* @param {integer} rotation - Rotation of the page in degree
*/
getARenderJS().getRotateJSAPI().registerNotifyPageRotatedEvent(function(documentId, pageNumber, rotation) {
console.log("Page rotated. DocumentId: " + documentId + " pageNumber: " + pageNumber + " rotation: " + rotation);
});
Intercept Hyperlinks
- Object: getARenderJS().getAnnotationJSAPI()
Here is an example of JS code allowing to register a method that will be called each time that an hyperlink is clicked.
var annotationjs;
function arenderjs_init(ajs)
{
ajs.onAnnotationModuleReady(
function(annotjs){
annotationjs=annotjs;
annotjs.registerFollowLinkHandler(followLink);
console.log(annotationjs.getDestinationTypes());
console.log(annotationjs.getActionTypes());
}
);
}
function followLink(docId, pageNumber, destination, action)
{
console.log([
"docId=" + docId,
"pageNumber=" + pageNumber,
"dest=" + destination, "action=" + action
].join());
console.log(annotationjs.getPropertyFromDestination(destination,"PAGE_TARGET"));
console.log(annotationjs.getPropertyFromAction(action,"GOTO"));
}
In this example, you can also observe how to visualize all existing properties in hyperlinks.
annotationjs.getDestinationTypes() and annotationjs.getActionTypes() contains the list of properties that can be asked for hyperlinks destinations and actions.
annotationjs.getPropertyFromDestination(destination,property) and annotationjs.getPropertyFromAction(action,property) allow to ask for a particular property once the action or destination have been received.
You will find following the list of properties for destinations :
Type | Description |
---|---|
PAGE_TARGET | Page number of the page targeted |
URI | URI address to go to |
You will find following the list of properties for actions that will indicate the type of fields you will find in the destination :
Type | Description |
---|---|
GOTO | The destination is a page number |
URI | The destination is an URI |
Create an highlight annotation
- Object: getARenderJS().getAnnotationJSAPI()
Function | Description |
---|---|
addAnnotation(id, type, x, y, w, h, page, color, opacity) | Create an annotation at the desired position to the given documentId |
/*
* Add an highlight annotation
*
* @param {string} documentId - ID of the document
* @param {string} type - the annotation type (only "Highlight" is supported)
* @param {integer} x - the annotation x coordinate
* @param {integer} y - the annotation y coordinate
* @param {integer} w - the annotation width
* @param {integer} h - the annotation height
* @param {page} page - the annotation page
* @param {string} color - the annotation color
* @param {float} opacity - the annotation opacity
*/
var documentId = getARenderJS().getCurrentDocumentId();
var type = "Highlight";
var x = 50;
var y = 150;
var w = 100;
var h = 50;
var page = 0;
var color = "#FF0000";
var opacity = 0.4;
getARenderJS().getAnnotationJSAPI().addAnnotation(
documentId, type, x, y, w, h, page, color, opacity);