Create a stamp / annotation on all pages

I would like to generate a stamp on all pages of a document. Ideally, the stamp should be dynamically generated with the stamp feature, standard or custom.

I got a solution with the watermark feature but it only works in webviewer, not when the pdf is downloaded. Also, I cannot use the feature to select a stamp with this solution.

I tried to overload the RubberStamp annotation tool, with the method described here : PDFTron

But I am unable to make it work, probably because the mouseleftUp is not called on the RubberStampTool but on another subtool which I cannot find programatically

One solution would be to copy an annotation on all pages of a document with a context button, but I have a hard time figuring how that could be done.

Any ideas to implement this?

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:

Hi Michael,

Just to clarify, what specifically are you looking for help with.

Would you like to copy an annotation to all pages?
or
Would you like to extend the rubberstamp tool to place the same annotation on all pages?

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

Hello Ahmad

The goal is to allow the user to place an annotation on all pages at once, at the same place.
My current solution, which works is this one :

const tool3 = documentViewer.getTool('AnnotationCreateRubberStamp') as Core.Tools.RubberStampCreateTool;

   

      tool3.addEventListener("annotationAdded", (annotationa) => {
        if(confirm("Do you want to copy the stamp to all pages?")) {
          const pagesCount = documentViewer.getPageCount();
          let pageLoop;
          const allAnnotations = [];
          if(pagesCount > 1 && annotationa.getPageNumber()==1) {
            for (pageLoop = 2; pageLoop <= pagesCount; pageLoop++) {
              let copyOfAnnotation = annotationManager.getAnnotationCopy(annotationa,{copyAssociatedLink : false});
              copyOfAnnotation.setPageNumber(pageLoop);
              copyOfAnnotation.setX(annotationa.getX());
              copyOfAnnotation.setY(annotationa.getY())
              annotationManager.addAnnotation(copyOfAnnotation);
              allAnnotations.push(copyOfAnnotation);
          }
            annotationManager.drawAnnotationsFromList(allAnnotations);  
          }

        }

      });

It is not very elegant though. Ideally, i’d like either to add a checkbox in the ToolStylePopup for the RubberStamp or to add another rubberstamp feature with the same options, but for all pages at once.

For the first solution (ToolStylePopup), i don’t see how to add items to the ToolStylePopup, and for the second solution, I can’t register twice the Rubberstamp.

Hi Michael,

To customize the ToolStylePopup you would need to create your own custom UI.
Here is the link to the tool style popup component: https://github.com/PDFTron/webviewer-ui/blob/8.2/src/components/ToolStylePopup/ToolStylePopup.js

For the Tool, you can create a new instance of rubberstamp tool and add an event listener to it similar to your earlier approach. Then you can use this guide to add your tool to the header.

Let me know if there are any issues.

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com