adobe / adobe/pdf-embed-api-samples
Annotation Selector is not valid for given xxx
- Dominant language
- JavaScript
- Stars
- 235
- Forks
- 140
- PR merge metrics
- No merged PRs in 30d
Description
### Expected Behaviour
For the given annotations to be added to a Document on preview file.
### Actual Behaviour
Annotations are not being added intermittently. Sometimes they are added and sometimes it fails. It fails most of the times.
### Reproduce Scenario (including but not limited to)
I've encountered this error when using:
`annotationManager.addAnnotations(annotations);
`
#### Steps to Reproduce
#### Platform and Version
PDF Embed API
#### Sample Code that illustrates the problem
```
var document_data = [{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "408abbe1-7b68-8c17-19h1-5a7aba9c891",
"type": "Annotation",
"motivation": "commenting",
"bodyValue": "Hi",
"target": {
"source": "6d07d124-ac85-43b3-a867-36930f502ac6",
"selector": {
"node": {
"index": 0
},
"opacity": 0.4,
"subtype": "note",
"boundingBox": [
578.1040491761639,
825.4109275434271,
595.711279100311,
842.0399780273438
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-27T13:11:27Z",
"modified": "2022-09-27T13:11:27Z"
},{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "8b9cb9db-e5a4-87ba-2ch7-6b18fabeba2",
"type": "Annotation",
"motivation": "commenting",
"bodyValue": "Test",
"target": {
"source": "6d07d124-ac85-43b3-a867-36930f502ac6",
"selector": {
"node": {
"index": 0
},
"opacity": 0.4,
"subtype": "note",
"boundingBox": [
384.42452001054556,
530.0007365938475,
402.0317499346927,
547.6079665179946
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-27T13:12:04Z",
"modified": "2022-09-27T13:12:04Z"
},{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "0aa999a7-9f5e-841f-02h9-fa094884abd",
"type": "Annotation",
"motivation": "commenting",
"bodyValue": "",
"target": {
"source": "6d07d124-ac85-43b3-a867-36930f502ac6",
"selector": {
"node": {
"index": 0
},
"quadPoints": [
168.85789087681306,
485.1357995831707,
314.6897057249698,
485.1357995831707,
168.85789087681306,
476.5010210724246,
314.6897057249698,
476.5010210724246,
313.7302858904425,
485.1357995831707,
565.0982825366074,
485.1357995831707,
313.7302858904425,
476.5010210724246,
565.0982825366074,
476.5010210724246,
28.78259503582041,
476.5010210724246,
235.05785945920002,
476.5010210724246,
28.78259503582041,
468.82566239620576,
235.05785945920002,
468.82566239620576
],
"opacity": 0.4,
"subtype": "highlight",
"boundingBox": [
168.85789087681306,
485.1357995831707,
235.05785945920002,
468.82566239620576
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-27T13:17:16Z",
"modified": "2022-09-27T13:17:16Z"
},{
"@context": [
"https://www.w3.org/ns/anno.jsonld",
"https://comments.acrobat.com/ns/anno.jsonld"
],
"id": "5298b8d4-3e27-85a3-92hc-3949dbbe8be",
"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.0399780273438,
595,
842.0399780273438
],
"strokeColor": "#fccb00",
"type": "AdobeAnnoSelector"
}
},
"creator": {
"id": "LMF-2",
"name": "LMF-2",
"type": "Person"
},
"created": "2022-09-27T13:34:59Z",
"modified": "2022-09-27T13:34: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: "xxxx",
/* 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/somefile.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: "somefile.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');
});
});
});
});
```
#### Logs taken while reproducing problem
Contributor guide
Assessment
This issue has not been assessed yet.