AnnotationChanged event triggers as soon as pdf is opened with linkAnnotationEvent

Which product are you using?

PDF.js Express Plus
PDF.js Express Version

8
Detailed description of issue
when i open the PDF, even though there is no annotation drawn, i am able to see annotation event getting triggered and it gives the action as add when i console

Expected behaviour
If there is any change with respect to annotation like export/import/ drawing a new annotation then only annotation changed event has to trigger.

Does your issue happen with every document, or just one?
all documents, but as per my observation if pdf is having borders in the page, then this issue occurs, for pdf without borders seems to work fine, i have uploaded an image, when the pdf opens which has border, that black border appears at end which is not done by us, and while importing annotations, sometimes annotation get imported as black box but the xfdf value given wont get binded back to pdf instead this black highlight becomes dominating.

Link to document
i feel the issue could also be due to LinkAnnotations

Code snippet

  annotationManager.addEventListener('annotationChanged', (annotations: any, action: any) => {
        let unique: any = [...this.annotationList.filter((ele: any) => ele.checked)];
        annotations.forEach((annot: any) => {
          annot.StrokeThickness = 3;
        });
        if (action === 'add') {}
})

image

@zserviss please help with suggestion

Hi @rakshitha_r,

Could you please send a PDF where you’re experiencing this issue?

Best Regards,
Zach Serviss
Platform Support Engineer

New_RakshithaTR_3915_Sep_InternetBill.pdf (85.9 KB)
hope this may help you

@zserviss , issue i noticed was that,

  1. if i upload a pdf which doesnt have links works fine, with the links on page load itself if will triggers annotationChangeEvent with action as add. i have customised my requirement like if action is add and there is no imported annotations i must show a popup to add comments, so with the above pdf, as soon as page loads it opens 3 popup as it is 3 page pdf with links at each page end.
  2. i have one more customised comments table, so based on click on row i am binding the xfdf data back to pdf, so here also if i have clicked on 3 rows, only 2 gets annotate back to pdf and 1 or 3 will be the hyperlink and gets highlighted with black color, so there by my one xfdf data doesnt get binded.

This is due to automatic linking where PDFjs Express parses through and creates hyperlinks to matching URLs.

You can disable this feature with this code: instance.Core.DocumentViewer.disableAutomaticLinking();.

https://pdfjs.express/api/Core.DocumentViewer.html#disableAutomaticLinking__anchor

Best Regards,
Zach Serviss
Platform Support Engineer

thanks for response @zserviss but i am getting this error
instance.Core.DocumentViewer.disableAutomaticLinking is not a function

You can ignore that error as its a type error on our end that were already looking into.

Best Regards,
Zach Serviss
Platform Support Engineer

Thanks zserviss, but I am not able to render xfdf data back to pdf

How are you importing the XFDF into the viewer?

Are you flattening the annotations after importing?

Best Regards,
Zach Serviss
Platform Support Engineer

const xfdfString = <?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4" /><fields /><annots><square page="3" rect="64,311.750,317,539.750" color="#FF0000" flags="print" name="fb32b83b-7dbc-c6c0-96be-0af5284a49ee" title="admin" subject="Rectangle" date="D:20230214225127+05'30'" width="3" creationdate="D:20230214225126+05'30'"/></annots><pages><defmtx matrix="1,0,0,-1,0,792" /></pages></xfdf>;
annotationManager.importAnnotations(xfdfString);

in this way i am importig back to pdf, but now it is not getting imported.

i have added code like this,

 instance.Core.DocumentViewer.disableAutomaticLinking();
      // listening to annotations based on add
      annotationManager.addEventListener('annotationChanged', (annotations: any, action: any) => {})

is this fine, when i am trying to import, it is not even hitting annotationManger?

@zserviss, default showing of linking issue got fixed but with error at the console, but now it is failing to create an annotation back to viewer and drawing annotation also fails. is there any other approach for this

Could you please provide a sample project?

Best Regards,
Zach Serviss
Platform Support Engineer

hi @zserviss ,
good day!
i am trying ti create a annotation but not able to find issue i am getting over there, now my issue is that, when i try to create an annotation, where links and all will be present, i get xfdfString as

<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4" /><fields /><annots><link page="0" rect="233.880,182.466,266.151,207.231" color="#000000" flags="print" name="45369d2a-1837-c12f-4d08-7899d3a03dba" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/"/></Action></OnActivation></link><link page="0" rect="265.401,182.466,293.919,207.231" color="#000000" flags="print" name="bfcedfc4-c804-bb14-991c-18d13924e2e2" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/"/></Action></OnActivation></link><link page="0" rect="320.936,182.466,350.205,207.231" color="#000000" flags="print" name="5f989ea2-803e-90d9-e48b-bc96378c53c2" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/"/></Action></OnActivation></link><link page="0" rect="349.454,182.466,380.974,207.231" color="#000000" flags="print" name="a73cbc1f-8b92-2a64-6abb-d1dfe506e49a" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/"/></Action></OnActivation></link><link page="0" rect="293.168,182.466,321.686,207.231" color="#000000" flags="print" name="759fe8f3-108f-1751-cfe3-b46e070426f3" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/"/></Action></OnActivation></link><link page="0" rect="37.255,528.436,116.806,565.960" color="#000000" flags="print" name="d14b444c-e807-5cf4-e66f-d5d88692ff4b" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/home"/></Action></OnActivation></link><link page="0" rect="86.036,504.421,106.299,526.935" color="#000000" flags="print" name="963d3cb6-6d2c-8e88-9726-c6f2107786c8" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/javascript:%3B"/></Action></OnActivation></link><link page="0" rect="114.554,505.922,195.606,518.680" color="#000000" flags="print" name="2db912fc-e85f-ae79-b09a-c5840a6bf276" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/javascript:%3B"/></Action></OnActivation></link><link page="1" rect="44.010,492.413,71.777,505.171" color="#000000" flags="print" name="65860ee0-8bb0-0c44-54ba-e88e4c065906" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,492.413,101.046,505.171" color="#000000" flags="print" name="112242ff-84c0-edbd-29d1-844e89a26fd9" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,460.893,71.777,473.651" color="#000000" flags="print" name="0ec39a41-c8db-8060-cb23-cce44259b171" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,460.893,101.046,473.651" color="#000000" flags="print" name="1ba98440-0d46-192d-f4ec-4e2a5655447a" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,428.623,71.777,441.381" color="#000000" flags="print" name="62edb884-1ac9-87fa-2986-565a3867a6ba" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,428.623,101.046,441.381" color="#000000" flags="print" name="ec901084-6cf8-efa3-a64e-60bb6bbbe85b" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,397.102,71.777,409.861" color="#000000" flags="print" name="cfe5b6f5-01ca-974e-5825-aea53eca5f86" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,397.102,101.046,409.861" color="#000000" flags="print" name="1655efcd-3f68-b8a6-58ce-684e94dd09b4" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,365.582,71.777,378.341" color="#000000" flags="print" name="5077450e-13fa-15ee-2886-06c9ece26dd6" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,365.582,101.046,378.341" color="#000000" flags="print" name="67ad1710-9f1d-7adc-8ecb-53bde1dab73a" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,334.062,71.777,346.820" color="#000000" flags="print" name="972b64c2-f708-8781-b2c7-bcd3c0df6428" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,334.062,101.046,346.820" color="#000000" flags="print" name="9a3f4454-1415-02ed-73c6-1ad5e3deeb21" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,302.542,71.777,315.300" color="#000000" flags="print" name="62f41376-816a-7a4d-8e88-ab99ebb120b5" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,302.542,101.046,315.300" color="#000000" flags="print" name="f434b877-2c89-9f8b-f762-2bff9fd2ffad" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="44.010,270.272,71.777,283.030" color="#000000" flags="print" name="27543314-6690-00bd-6e62-9c49d2aae7db" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="86.036,270.272,101.046,283.030" color="#000000" flags="print" name="dc9f6c87-d82c-9c65-35b9-3e4bde0785aa" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="javascript:void(0);"/></Action></OnActivation></link><link page="1" rect="37.255,528.436,116.806,565.960" color="#000000" flags="print" name="82dfe050-12f1-1981-e7dc-b2730254559f" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/home"/></Action></OnActivation></link><link page="1" rect="86.036,521.682,106.299,544.196" color="#000000" flags="print" name="30245359-7d7b-bc33-91fc-feedcaaad508" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/javascript:%3B"/></Action></OnActivation></link><link page="1" rect="114.554,523.183,195.606,535.941" color="#000000" flags="print" name="2bd9eaa1-c083-fe15-72b5-120f18cc5d90" subject="Annotation" date="D:20230308220212+05'30'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="http://localhost:4200/javascript:%3B"/></Action></OnActivation></link><square page="1" rect="119,24.960,712,199.960" color="#FF0000" flags="print" name="01823875-c1ba-6c07-d559-9d0e3eab9522" title="adminuser" subject="Rectangle" date="D:20230308220253+05'30'" width="3" creationdate="D:20230308220252+05'30'"/></annots><pages><defmtx matrix="1,0,0,-1,0,594.95996" /></pages></xfdf>

which has soo many links and all, i just drawn in 2nd page, but got pageNumber as 1 with
this logic

 const pageNumber = annotationManager.getAnnotationsList()[0].getPageNumber();

so is there anyway where in i can get annotation of drawn co-ordinates itself instead of those links.

Hi there,

After disabling automatic linking, you could remove all annotations via deleteAnnotations:
annotationManager.deleteAnnotations(annotationManager.getAnnotationsList())
and then create the annotations. Then exporting them via exportAnnotations should only show you the annotation you created.

Best regards,
Kevin Kim

hi @zserviss
i have added instance.Core.DocumentViewer.disableAutomaticLinking(); but this gave me console error instance.Core.DocumentViewer.disableAutomaticLinking is not a function so i was not even able to draw annotations using rectangular box. so i removed that

Hi there,

disableAutomaticLinking works on our demo page:

Could you please try again with documentViewer with lowercase ‘d’?

Best Regards,
Kevin Kim