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.
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.
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