Skip to main content
Known Participant
September 30, 2022
Question

Annotation selector is not valid for given {id}

  • September 30, 2022
  • 5 replies
  • 18585 views

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>
    This topic has been closed for replies.

    5 replies

    Raymond Camden
    Community Manager
    Community Manager
    December 15, 2022

    The fix for this has been deployed to production, but note that bounding box coordinates must be correct.

    Inspiring
    November 3, 2023

    @Raymond Camden still encountering this issue..

    {"source":"da5e2508-bab0-428d-7570-08dbdb2aec54","selector":{"node":{"index":0},"quadPoints":[136.32046054209644,620.0642840009594,714.1472775245862,620.0642840009594,136.32046054209644,610.2393859438714,714.1472775245862,610.2393859438714,136.32046054209644,610.2393859438714,722.7440633245383,610.2393859438714,136.32046054209644,599.8004317582154,722.7440633245383,599.8004317582154,136.32046054209644,599.8004317582154,776.7810026385225,599.8004317582154,136.32046054209644,589.3614775725594,776.7810026385225,589.3614775725594,136.32046054209644,589.3614775725594,469.13888222595347,589.3614775725594,136.32046054209644,578.9225233869033,469.13888222595347,578.9225233869033,223.5164307987527,589.3614775725594,749.7625329815304,589.3614775725594,223.5164307987527,578.9225233869033,749.7625329815304,578.9225233869033,136.32046054209644,578.9225233869033,695.7255936675463,578.9225233869033,136.32046054209644,568.4835692012473,695.7255936675463,568.4835692012473,136.32046054209644,568.4835692012473,168.25137922763253,568.4835692012473,136.32046054209644,558.0446150155913,168.25137922763253,558.0446150155913,178.69033341328856,568.4835692012473,490.6308467258336,568.4835692012473,178.69033341328856,558.0446150155913,490.6308467258336,558.0446150155913,136.32046054209644,558.0446150155913,704.9364355960662,558.0446150155913,136.32046054209644,547.6056608299352,704.9364355960662,547.6056608299352,136.32046054209644,547.6056608299352,469.13888222595347,547.6056608299352,136.32046054209644,537.1667066442792,469.13888222595347,537.1667066442792,241.32405852722476,547.6056608299352,731.9549052530583,547.6056608299352,241.32405852722476,537.1667066442792,731.9549052530583,537.1667066442792,136.32046054209644,537.1667066442792,735.6392420244663,537.1667066442792,136.32046054209644,526.7277524586232,735.6392420244663,526.7277524586232,136.32046054209644,526.7277524586232,773.0966658671144,526.7277524586232,136.32046054209644,516.9028544015351,773.0966658671144,516.9028544015351,136.32046054209644,516.2887982729671,744.8500839529863,516.2887982729671,136.32046054209644,506.4639002158791,744.8500839529863,506.4639002158791,136.32046054209644,506.4639002158791,469.13888222595347,506.4639002158791,136.32046054209644,496.0249460302231,469.13888222595347,496.0249460302231,223.5164307987527,506.4639002158791,744.8500839529863,506.4639002158791,223.5164307987527,496.0249460302231,744.8500839529863,496.0249460302231,136.32046054209644,496.0249460302231,754.0609258815064,496.0249460302231,136.32046054209644,485.58599184456705,754.0609258815064,485.58599184456705,136.32046054209644,485.58599184456705,727.0424562245144,485.58599184456705,136.32046054209644,475.147037658911,727.0424562245144,475.147037658911,136.32046054209644,475.147037658911,469.13888222595347,475.147037658911,136.32046054209644,464.708083473255,469.13888222595347,464.708083473255,241.32405852722476,475.147037658911,727.0424562245144,475.147037658911,241.32405852722476,464.708083473255,727.0424562245144,464.708083473255,136.32046054209644,464.708083473255,730.7267929959223,464.708083473255,136.32046054209644,454.2691292875989,730.7267929959223,454.2691292875989],"opacity":1.0,"subtype":"highlight","boundingBox":[136.32046054209644,620.0642840009594,776.7810026385225,454.2691292875989],"inkList":null,"strokeColor":"#F8D147","strokeWidth":0,"type":"AdobeAnnoSelector","styleClass":null}}

    Here is the JSON of the target annotation being loaded. Its a highlight annotation.

     



    Raymond Camden
    Community Manager
    Community Manager
    November 3, 2023

    All I can suggest is ensuring the bounding boxes are right. If you do, and the issue still remains, I'd need a reproducable case I can report internally, preferably an html file with the JS and everything all in that one file.

    Raymond Camden
    Community Manager
    Community Manager
    October 24, 2022

    As an update, engineering has been able to diagnose the issue, and it's closely related to what yall are seeing - not the SIZE of the quads but invalid sized ones. No ETA on a fix, but progress is being made. 

    Known Participant
    November 2, 2022

    Hey @Raymond Camden ,

     

    Any update on this issue?

    Raymond Camden
    Community Manager
    Community Manager
    November 2, 2022

    I can tell you, internally, work is being done. Not sure I'm allowed to say more so I'll shut up, but it's definitely being worked on.

    Raymond Camden
    Community Manager
    Community Manager
    October 10, 2022

    To all in this thread, I am updating the reported bug with the additional folks reporting issues. That's all I can do at the moment.

    Participating Frequently
    October 10, 2022

    @Raymond Camden thank you so much for your quick response! We look forward to any further help you can provide. 

    Known Participant
    October 6, 2022

    I was really hoping to get some better help from this channel. Topics that were opened after mine were answered, but mine is just being ignored. Should I have provided better information or what can I do to get some guidance?

     

    CC @Raymond Camden

    Raymond Camden
    Community Manager
    Community Manager
    October 6, 2022

    Right now, forum support is done by a few different individuals, and sometimes scheduling makes it difficult to check back as quickly as possible. 

    Participating Frequently
    October 11, 2022

    I'm confused - you said you tried it and it worked. Where is it throwing the client id error?


    @Raymond Camden yeah, it threw that error on my local machine, then I switched back to the new one, then back to the old one and it worked (I know, very confusing). But when I tried it on our staging server (corceptcp.uat.cm.skyscraperstudios.com, which is using the new viewer at this moment), I got the key error.

    Known Participant
    October 3, 2022

    @Raymond Camden Regarding your comment on here: https://community.adobe.com/t5/document-services-apis-discussions/document-annotations-not-showing/td-p/13237425

     

    Do you still need an online example? Or is this source code enough?

     

    Kind regards

    Raymond Camden
    Community Manager
    Community Manager
    October 6, 2022

    Yes please, if you can put something together that is complete, it would help. A CodePen would be awesome.