Detailed description of issue
I have a table, where in i will be storing all the selected Annotation xml format data with help of instance.Core.annotationManager.exportAnnotations(); value so this value will be stored in each row.
the output i get appears like this from the value:
on each row, i have kept checkbox, so if that is checked, i am binding the output from image i am not getting where i am going wrong, i am getting an error as Cannot read properties of undefined (reading ‘addEventListener’)
Expected behaviour
{Provide a screenshot or description of the expected behaviour}
when i click on the checkbox, the annotation must be imported and should be shown on the pdf. Does your issue happen with every document, or just one?
yes
Link to document
{Provide a link to the document in question if possible}
Code snippet
setAnnotation(event: any) {
this.renderingInstance.documentViewer.addEventListener(‘documentLoaded’, async () => {
const xfdfString = event.annotationString;
this.renderingInstance.Core.annotationManager.importAnnotations(xfdfString);
});
}
where, event.annotationString contains the param as in screenshot under [promiseResult],
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
Best Regards,
Kevin Kim
Web Development Support Engineer
PDFTron Systems, Inc.
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
hi Kevin,
thanks for response.
Kevin, my requirement is that, when i add an annotation, i am capturing and storing that out of WebViewer, when i am going to click on checkbox which has no connection to webViewer but i will have that xfdfString data, so it is like i have to make dummy event call inside webViewer and make my xfdfString to show annotation on webViewer.
this line is giving me error as well, document.getElementById Object is possibly ‘null’.
Kevin, by modify based on my requirement i am now able to show annotation on the webviewer, but when i have multiple pages, based on my checkbox check, i am able to get annotation box, but now i am in page1, but the checkbox i selected has annotation in second page or in end of the page means, it still remains in top section of page, and doesnt page scroll to show particular annotated box., but in my xml string i am able to see page number as 1 or 0.
this set of code is importing the annotation on pdf perfectly, but it is not scrolling to that particular row or page, it remains where user has scrolled manually but annotation will be drawn, when user manually scrolls, then we will be able to see.
Best Regards,
Kevin Kim
Web Development Support Engineer
PDFTron Systems, Inc.
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
thanks for response Kevin,
for example i made 2 annotations, one at first row section of page and other one at last row section of page, but when i want to import that annotation based on selection of checkbox, it stays at first page top, but doesnt show that last row, is there anyway where in we can show that particular section when clicked.
If I am understanding correctly, you would like to jump to a particular section based on the imported annotation’s location.
Since the XFDF data from the annotation contains the coordinates, you can use the displayPageLocation API: PDFJS Express WebViewer Class: DocumentViewer
and do something like this:
Best Regards,
Kevin Kim
Web Development Support Engineer
PDFTron Systems, Inc.
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
thanks Kevin, your solution made my day, currently i am looking for deleting selected annotation by converting to actual object.
i searched and i tried by saving the actual annotation and passing same annotation when i need to delete so that actual annotation will be present but i failed in this as well.
any example? it would really help me
Best Regards,
Kevin Kim
Web Development Support Engineer
PDFTron Systems, Inc.
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
You will need to change the layer in the dev-tools from ‘top’ to ‘webviewer-1’ to be in the context of WebViewer:
Best Regards,
Kevin Kim
Web Development Support Engineer
PDFTron Systems, Inc.
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
got it Kevin i will try now, i have changed in developer console and tried but still get same issue, even in application also same issue. here i should be able to select checkbox show annotation on PDF, when unchecked remove annotation from pdf, so multiple annotations can be added/removed based on selection of checkbox.
here, deleting all annotations at one time works fine with this code,
One thing to note is that once you imported the xfdfString after calling importAnnotations, you will no longer need to reference it by the xfdfString but rather the annotation that was imported.
So in this case, after you import and have an event that triggers when importing, you have the annotation properties:
annotationManager.addEventListener(‘annotationChanged’, (annotations, action, {imported}) => {
if (imported) {
console.log(‘imported annotation’, annotations[0])
documentViewer.displayPageLocation(annotations[0].PageNumber, annotations[0].X, annotations[0].Y);
// if you want to delete this annotation that was just imported, you can use
// annotationManager.deleteAnnotation(annotations[0])
}
});
Best Regards,
Kevin Kim
Web Development Support Engineer
PDFTron Systems, Inc.
Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here
hi Kevin,
i need to delete annotation which is already present on pdf, based on checkbox uncheck i need to delete one particular annotation which is already present.
i will try and keep you posted.
thanks a lot for your support Kevin, as my requirement was quite different, so i saved the creationdate of annotation at time of export and by comparing that date with list of getAnnotations i was able to compare and delete the particular annotation.
your each message help me to fix my issues.
Thanks again
i have got around 8 annotations drawn across 3 pages of pdf and stored in a variable, when i choose selectAll, there is missing annotations in 1st page sometimes, 2nd page sometimes, i am not sure for what reason this issue is arising, when i select individual checkbox, i get annotation draw perfectly, but when i checkfor all annotations at a time, it is getting missed from getting drawn, but i am able to get 8 times detection, i mean all 8 items are going in list.
so when i choose on selectAll, selectAllAnnotations() method hits and here, i am calling setAnnotation() method, so object by object, the annotations are going and getting added to pdf with this.setAnnotationEvent. last set of code.
am i wrong here?
thanks