Question
Annotation selector is not valid for given {id}
Hi,
I've encountered this error when using
annotationManager.addAnnotations(annotations);It is really difficult to debug because it works fine on a PDF, until you add a certain annotation and then it stops working. From my best guess It seems to happen when the quadPoints contain more than 20+ items.
I will paste my full source code below.
Please advise urgently.
Kind regards
<script>
var document_data = [{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "4ababa2a-2de5-8e18-b0h9-c85939ab8a4",
"type": "Annotation",
"motivation": "commenting",
"bodyValue": "hi",
"target": {
"source": "6d07d124-ac85-43b3-a867-36930f502ac6",
"selector": {
"node": {
"index": 0
},
"opacity": 0.4,
"subtype": "note",
"boundingBox": [
578,
825,
595,
842
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-30T08:55:18Z",
"modified": "2022-09-30T08:55:18Z"
},{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "ebb99746-af83-8d67-55h1-9adbc9ac8a4",
"type": "Annotation",
"motivation": "commenting",
"bodyValue": "hi2",
"target": {
"source": "6d07d124-ac85-43b3-a867-36930f502ac6",
"selector": {
"node": {
"index": 0
},
"quadPoints": [
90,
684,
506,
684,
90,
671,
506,
671,
90,
671,
385,
671,
90,
657,
385,
657
],
"opacity": 0.4,
"subtype": "highlight",
"boundingBox": [
90,
684,
385,
657
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-30T08:55:38Z",
"modified": "2022-09-30T08:55:38Z"
},{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "87b29110-8be8-813f-4bh3-c919ba82981",
"type": "Annotation",
"motivation": "commenting",
"bodyValue": "",
"target": {
"source": "6d07d124-ac85-43b3-a867-36930f502ac6",
"selector": {
"node": {
"index": 0
},
"quadPoints": [
309.9162011173185,
739.3463687150838,
505.44692737430177,
739.3463687150838,
309.9162011173185,
725.659217877095,
505.44692737430177,
725.659217877095,
89.9441340782123,
725.659217877095,
505.44692737430177,
725.659217877095,
89.9441340782123,
711.9720670391062,
505.44692737430177,
711.9720670391062,
89.9441340782123,
711.9720670391062,
306.9832402234637,
711.9720670391062,
89.9441340782123,
698.2849162011173,
306.9832402234637,
698.2849162011173
],
"opacity": 0.4,
"subtype": "highlight",
"boundingBox": [
309.9162011173185,
739.3463687150838,
306.9832402234637,
698.2849162011173
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-30T09:04:59Z",
"modified": "2022-09-30T09:04:59Z"
},];
const annotations = document_data;
/*
Copyright 2020 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it. If you have received this file from a source other than Adobe,
then your use, modification, or distribution of it requires the prior
written permission of Adobe.
*/
var viewerConfig = {
/* Enable commenting APIs */
enableAnnotationAPIs: true, /* Default value is false */
embedMode: "FULL_WINDOW",
};
/* Wait for Adobe Document Services PDF Embed API to be ready */
document.addEventListener("adobe_dc_view_sdk.ready", function () {
const eventOptions = {
listenOn: [
"ANNOTATION_ADDED", "ANNOTATION_CLICKED",
"ANNOTATION_UPDATED", "ANNOTATION_CLICKED",
"ANNOTATION_DELETED", "ANNOTATION_CLICKED",
]
}
const profile = {
userProfile: {
name: 'LMF-2',
}
};
/* Initialize the AdobeDC View object */
var adobeDCView = new AdobeDC.View({
/* Pass your registered client id */
clientId: "removed_for_security",
/* Pass the div id in which PDF should be rendered */
divId: "adobe-dc-view",
});
/* Invoke the file preview API on Adobe DC View object and return the Promise object */
var previewFilePromise = adobeDCView.previewFile({
/* Pass information on how to access the file */
content: {
/* Location of file where it is hosted */
location: {
url: "https://some.domain.com/public/s3_files/uploadsPy3quFjSCSQF8vNJ4tOSCDWxlJhCfh8QAP1Kr0OG.pdf",
/*
If the file URL requires some additional headers, then it can be passed as follows:-
header: [
{
key: "<HEADER_KEY>",
value: "<HEADER_VALUE>",
}
]
*/
},
},
/* Pass meta data of file */
metaData: {
/* file name */
fileName: "Py3quFjSCSQF8vNJ4tOSCDWxlJhCfh8QAP1Kr0OG.pdf",
/* file ID */
id: "6d07d124-ac85-43b3-a867-36930f502ac6"
}
}, viewerConfig);
adobeDCView.registerCallback(
AdobeDC.View.Enum.CallbackType.GET_USER_PROFILE_API,
function() {
return new Promise((resolve, reject) => {
resolve({
code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
data: profile
});
});
},
{});
/* Use the annotation manager interface to invoke the commenting APIs*/
previewFilePromise.then(function (adobeViewer) {
adobeViewer.getAnnotationManager().then(function (annotationManager) {
annotationManager.registerEventListener(
function(event) {
var status = true;
for (let i = 0; i < annotations.length; i++) {
if(annotations[i].id == event.data.id){
status = false;
}
}
if(event.type == "ANNOTATION_DELETED" || event.type == "ANNOTATION_UPDATED"){
status = true;
}
// "ANNOTATION_UPDATED", "ANNOTATION_CLICKED",
if(status) {
console.log(event);
console.log('qawsed');
var workflow_id = $('.workflow_id').val();
var document_data = JSON.stringify(event.data, null, 2);
// var document_data = event.data;
$.ajax({
url : base_url+'/correspondence/pdf-comment-save',
type : "post",
data: {
'_token' : csrf_token,
'data' : document_data,
'type' : event.type,
'workflow_id' : workflow_id
},
success : function(data){
var response = $.parseJSON(data);
if(response.status == true) {
showMessage('success',response.message);
} else {
showMessage('error',response.message);
}
}
});
}
},
eventOptions
);
/* API to add annotations */
annotationManager.addAnnotations(annotations)
.then(function () {
console.log("Annotations added through API successfully")
})
.catch(function (error) {
console.log(error)
// console.log('1');
});
/* API to get all annotations */
annotationManager.getAnnotations()
.then(function (result) {
console.log("GET all annotations", result)
})
.catch(function (error) {
console.log(error)
// console.log('2');
});
/* API to delete annotations based on annotation ID filter */
var filter = {
annotationIds: ["3adeae16-a868-4653-960e-613c048dddc5", "079d66a4-5ec2-4703-ae9d-30ccbb1aa84c"]
};
annotationManager.deleteAnnotations(filter)
.then(function () {
console.log("Deleted annotations based on annotation ID filter.")
})
.catch(function (error) {
console.log(error)
// console.log('3');
});
/* API to delete annotations based on page range filter */
filter = {
pageRange: {
startPage: 4,
endPage: 6
}
};
annotationManager.deleteAnnotations(filter)
.then(function () {
console.log("Deleted annotations based on page range filter")
})
.catch(function (error) {
console.log(error)
// console.log('4');
});
/* API to get annotations after deletion */
annotationManager.getAnnotations()
.then(function (result) {
console.log("GET annotations result after deleting annotations", result)
})
.catch(function (error) {
console.log(error)
// console.log('5');
});
});
});
});
</script>