Want to set the default color of the reactangle tool

Which product are you using?
PDF.js Express Plus

PDF.js Express Version
8.7.4

Detailed description of issue

How can I change the color of the rectangle tool programmatically with dynamic value ?

 documentViewer.addEventListener('documentLoaded', async () => {
      setIsDocumentLoadedSuccessfully(true);
      const rectangleTool = documentViewer.getTool('AnnotationCreateRectangle');
      // Set default styles
      rectangleTool.setStyles({
        fillColor: '#FF0000',
        strokeColor: '#000000',
        strokeWidth: 2,
      })
    });

I am trying to change the color like above code but it’s but working

Hello Shahid,

You can change the color of the rectangle tool programmatically like so:

      documentViewer.addEventListener('documentLoaded', async () => {
        setIsDocumentLoadedSuccessfully(true);
        const rectangleTool = documentViewer.getTool('AnnotationCreateRectangle');
        // Set default styles
        rectangleTool.setStyles({
          FillColor:  new Annotations.Color(255, 0, 0),
          StrokeColor:  new Annotations.Color(0, 0, 0),
          StrokeWidth: 2,
        })
      });

Best Regards,
Darian

1 Like

Thanks you @darian.chen this solution is working.

1 Like