Responding to a Copy/Paste of an annotation

Posted by: aheath on 15 December 2022, 7:41 pm EST

    • Post Options:
    • Link

    Posted 15 December 2022, 7:41 pm EST

    Hi,

    Is there a way to respond to the copy and paste of an annotation? OnBeforeAddAnnotation and onAfterAddAnnotation are the closest events I found but I specifically need to know when a paste has been done so I can re-position the pasted annotation at the cursor. Is there a simple way to accomplish this? Thanks

  • Posted 18 December 2022, 9:38 pm EST

    Hi,

    We are sorry, there is no direct way for this but you may customize the paste shortcut using the following code with GcPdfViewer version 4.0.0.

    const viewer = new GcPdfViewer("#viewer", { 
    		workerSrc: "/documents-api-pdfviewer/demos/product-bundles/build/gcpdfviewer.worker.js",		
    		supportApi: { 
    			apiUrl: window.top.SUPPORTAPI_URL,            
    			token: window.top.SUPPORTAPI_TOKEN,
    			webSocketUrl: false
    		},
            shortcuts: {
                "V":{
                    ctrl: true,
                    tool: function(){
    
                        viewer.execPasteAction().then(function(e){
    			// flag variable for checking the paste operation
                            console.log(e);
                        });
                    }
                }				
            }
    	});

    Along with this code, you may handle the OnAfterAddAnnotation event and do the needful with the pasted annotation.

    Regards,

    Manish Gupta

  • Posted 2 February 2023, 4:13 am EST

    Thanks Manish!

    There seems to be a bug with execPasteAction and it doesn’t respect the pageIndex passed to it. We’re trying to place the pasted annotation at specific coordinates on a specific page. It seems like there’s a version of execPasteAction that allows x, y, and pageIndex parameters but pageIndex doesn’t seem to work and pasted items always appear on the first page. Could you provide an example of using execPasteAction in this way?

    Also, what’s the best way to convert page coordinates (from mouse position for example) to pdf coordinates? We have a method that calculates the position using the viewPort and pagebounds but I’m wondering if there’s a more straightforward way.

    Thanks

    Anthony

  • Posted 7 February 2023, 3:06 am EST - Updated 7 February 2023, 3:11 am EST

    Hi,

    We have tried the below code snippet, and it is working fine on our end. Please refer to the following code snippet and an attached gif of the observation and if the issue persists please share a working sample that replicates the issue so that we could investigate it further and help you accordingly.

    	shortcuts: {
    			"V": {
    				ctrl: true,
    				tool: function () {
    					viewer.execPasteAction({ x: 10, y: 10, pageIndex: 1 }).then(function (e) {
    						// flag variable for checking the paste operation
    						console.log(e);
    					});
    				}
    			}
    		}

    For the second issue, we are unable to find any public API to achieve this hence, we have escalated this issue to the concerned team for further investigation. We will update you as soon as we get any information from the team. the internal ID for this issue will be DOC-5118

    Regards,

    Avinash

  • Posted 26 April 2023, 6:23 pm EST

    Hi,

    Please refer to the following code snippet to add the Annotation on the specified path on Mouseclick:

    document.addEventListener("click", (e) => {
      const target = (e["path"] || (e["composedPath"] && e["composedPath"]()) || [])[0] || e.target, page = target.closest(".page");
      if(target.closest(".gc-annotation"))
        return;
      if(page) {
        const pageIndex = page.getAttribute("data-index") * 1, pageLoc = viewer.getPageLocation(pageIndex), scale = viewer.getViewPort(pageIndex).scale;
        const x = (e.clientX - pageLoc.x) / scale, y = (e.clientY - pageLoc.y) / scale;
        const rect = viewer.changeBoundsOrigin(pageIndex, [x, y, x + 20, y + 20], "TopLeft", "BottomLeft");
        viewer.addAnnotation(pageIndex, { annotationType: 1 , contents: "Text annotation content", rect });
      }
    });

    This method uses the getPageLocation() to get the position of the page view relative to the browser window.

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels