Custom Redact button with Rectangle annotation


How can I make a custom redact annotation with rectangle which has black fill color automatically and remove the options to select color, opacity and thickness?

Hi there,

PDF.js Express does not support redaction unfortunately (if you want redaction you should take a look at our sister product).

If you wanted to fake it, there was a similar issue here you can reference, but you would use a RectangleCreateTool instead.

To remove the options to change the color etc, you can use the disableElements API to remove the elements you want when the annotation is selected.

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

   instance.on('annotationSelected', ([annot]) => {
      if(annot instanceof Annotations.RectangleAnnotation) {
      } else {

Something like this should help.


I used the above code and it gives this error.

When I replace the LineCreateTool with RectangleCreateTool I get this error

Hi sorry, it should be annotManager.on('annotationSelected')..., thats my bad!

Regarding your second reply, that’s the same issue as this ticket so we’ll handle that there.