Create image stamp annotations getting internal server error

I want to add image stamp for 6 pages of pdf in a single click.I tried below method to add stamp but i got “Internal server error”.

instance.setHeaderItems(function(header) {
                type: 'actionButton',
                img: '<svg xmlns="" viewBox="0 0 24 24"><path d="m0 0h24v24h-24z" fill="none"></path><path d="m21 19v-14c0-1.1-.9-2-2-2h-14c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zm-12.5-5.5 2.5 3.01 3.5-4.51 4.5 6h-14z"></path></svg>',
                onClick: function() {

                    var pages=docViewer.Pq.length;
                    async function onSavetwo() {

                        for (i = 1; i <= pages; i++) {
                            var stampAnnot = new Annotations.StampAnnotation();
                            stampAnnot.PageNumber = i;
                            stampAnnot.X = 100;
                            stampAnnot.Y = 250;
                            stampAnnot.Width = 275;
                            stampAnnot.Height = 40;
                            stampAnnot.ImageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB.....';
                            stampAnnot.Author = await annotManager.getCurrentUser();




The below pdf i have used


I have tried first two pages image stamp annotations it is working morethan 3 page pdf getting this error.Please help.


I don’t think the code you sent is what’s causing that error. The code you sent makes no requests to the API. Can you please confirm you sent the correct code snippet?

Also PS, I’m not sure where you found that docViewer.Pq.length code, but the best way to get the number of pages is this:

const pages = docViewer.getDocument().getPageCount()

Thank you,