Custom Rubber Stamp

This is just a question.
Can be put custom rubber stamp after we purchase the license.
For example i have to put stamp of 3 line:
" Exhibit
1235332
03-07-20"
If custom rubber stamp feature is not there then can we do it via calling some API
or slight modification in code.

2 Likes

Hey there,

Thanks for trying out PDF.js Express!

Custom rubber stamps can be created by creating a canvas, drawing whatever you want on it, calling toDataURL, then setting that as the ImageData for a stamp annotation.

Here is an example of what you might do:

const stampAnnot = new Annotations.StampAnnotation();
stampAnnot.PageNumber = 1;
stampAnnot.X = 100;
stampAnnot.Y = 250;
stampAnnot.Width = 275;
stampAnnot.Height = 40;

// create a canvas in memory to draw your text to
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');

// Your own function to add text to a canvas using the HTML5 canvas API
drawTextToCanvas(context, 'Exhibit 1235332 03-07-20')

// convert your canvas to a data URL
const dataURL = canvas.toDataURL(); 

// put your data URL here
stampAnnot.ImageData = dataURL;

annotManager.addAnnotation(stampAnnot);
annotManager.redrawAnnotation(stampAnnot);

I hope this helps!

Logan

Thank you logan for the code, just have small doubt
that the ā€œAnnotationsā€ object is always showing ā€œundefinedā€ when
I try to load it in ā€œ/samples/realtime-collaboration.jsā€ after below line:
const { docViewer, annotManager } = instance;

Could you please help me by mentioning where i can
put the code snippet provided by you or how to remove this ā€œundefined errorā€

Regards

Hi,

The code I sent should be put inside the ā€˜documentLoadedā€™ event.

WebViewer({...}).then(instance => {
   const { docViewer, annotManager, Annotations } = instance;

   docViewer.on('documentLoaded', () => {
      // the code I sent
   })
})

Hope this helps!

Thanks,
Logan

Hi Logan,

How i can disable the custom rubber stamp tab ?

Thanks

Hey Tony, I believe I answered this question in your other ticket. If not, please open a new ticket,