We have a collection of png’s we would like to use for the standard stamps dropdown that are behind a servlet with authentication enabled. Is there any support for calling setStandardStamps with urls but providing a token to use for the calls? We could add the token as a url parameter but for security purposes do not wish to do so.
We are able to make the call upfront and provide data urls to webviewer via setStandardStamps, but doing that method we lose access to the stamp id which we need to provide to our backend on save (getOriginalUrl has the stamp id in the url for ones loaded via web call where as it is empty for data urls).
If there was a way on the annotationAdded event to know which standard stamp was just added, we could easily add the stamp id to the custom data but we have not been able to find a way to identify which stamp was applied as even the image data appears to be modified from what was provided originally.
Thank you for contacting WebViewer Support. The setstandardstamps API take dataURI as an input, so one thing you can do is convert the string to a base 64 string and pass them to setstandardstamps.
For knowing which stamp annotation was added, you could do something like the following
WebViewer({}, document.getElementById('viewer')).then(instance => {
const { annotationManager } = instance.Core;
const { Annotations } = instance;
annotationManager.addEventListener('annotationChanged', (annotations, action) => {
if (action === 'add' && annotations[0] instanceof Annotations.StampAnnotation ) {
// can set the custom data of annotation here
}
});
});
Please let me know if the above help or if you want me clarify anything
Best Regards,
Andrew Yip
Software Developer
PDFTron Systems, Inc. www.pdftron.com
Thanks for the response - however we have tried exactly that, and as far as we can tell nothing exists on the annotations[0] object to identify which stamp was just added. Even the getImageData() method returns a base 64 image that is different than what was provided originally in the setStandardStamps call. It is worth noting we’ll have several stamps, so we need to be able to be able to map back to a stamp id from the annotations[0] object to be able to set custom data properly
The annotationChanged event will trigger whenever you add an annotation so you will have access to the stamp annotation that was just added. You could call exportAnnotations inside of the event to get the xml data of the stamp annotation that was created. From there the ‘name’ attribute should be unique for each annotations.