Snap viewport to next unsigned signature

Which product are you using?
PDF JS Express

PDF.js Express Version

Im looking for a way to snap the current viewport to a signature annotation. Currently I get the page number and set the viewer to view that page but depending on the zoom level the annotation could be above or below the viewport.

I see that you can get the viewport coordinates, but I cant find a place to set them based off the X/Y values of the annotation.

Code snippet

function GetNextSignature() {
            const signatureWidgetAnnots = annotManager.getAnnotationsList().filter(
                annot => annot instanceof Annotations.SignatureWidgetAnnotation
            );
            var found_sig = false;
            signatureWidgetAnnots.forEach(widget => {
                if (!found_sig) {
                    if (widget.fieldName.includes('CT_Signature_')) {
                        console.log(widget);
                        const isSigned = !!widget.annot;
                        if (!isSigned) {
                            found_sig = true;
                            docViewer.setCurrentPage(widget.PageNumber);
                        }
                    }
                }
            });
        }

Hello, Iā€™m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

For anybody who comes across this, I got it to work this way. Not sure if its the best way to do it but it snaps to the next signature and takes the users zoom into account.

function GetNextSignature() {
            
            const signatureWidgetAnnots = annotManager.getAnnotationsList().filter(
                annot => annot instanceof Annotations.SignatureWidgetAnnotation
            );
            var found_sig = false;
            signatureWidgetAnnots.forEach(widget => {
                if (!found_sig) {
                    if (widget.fieldName.includes('CT_Signature_')) {
                        
                        const isSigned = !!widget.annot;
                        if (!isSigned) {
                            found_sig = true;

                            const pageNumber = widget.PageNumber;
                            const pagePoint = {
                                x: widget.X,
                                y: widget.Y
                            };
                            //Get the window point for the annotation
                            const displayMode = docViewer.getDisplayModeManager().getDisplayMode();
                            const windowPoint = displayMode.pageToWindow(pagePoint, pageNumber);

                            
                            var zoom = docViewer.getZoom();
                            var padding = 0;
                            //Adjust the padding based on the zoom level
                            if (zoom >= 1) padding = (10 / zoom) * 20 + 50;
                            else padding = 200;
                            
                            //Set the viewport to the signature
                            docViewer.zoomTo(zoom, windowPoint.x, windowPoint.y - padding);
                            
                            
                        }
                    }
                }
            });
            if (!found_sig) {
                alert("All signature fields signed");
            }
        }
2 Likes