Incorrect opacity for StampAnnotation on Chrome

Which product are you using?
PDF.js Express Plus 8.7.4

Detailed description of issue
Hi there!

Let’s try this repo as our base, with upgrading library version to 8.7.4.
Let’s make some changes in code:

  1. ‘/files/PDFTRON_about.pdf’ - set correct file name in line 13
  2. Add several stamps like below:
        // add stamps
        for (let [x, y] of [[200, 500], [200, 550], [200, 600]]) {
          const stamp = new Annotations.StampAnnotation();
          stamp.PageNumber = 1;
          stamp.X = x;
          stamp.Y = y;
          stamp.Height = 20;
          stamp.Width = 20;
          stamp.setImageData('/goku.png');
          stamp.Opacity = 0.5;
          stamp.ReadOnly = true;
          annotManager.addAnnotation(stamp);
          // need to draw the annotation otherwise it won't show up until the page is refreshed
          annotManager.redrawAnnotation(stamp);
        }

In my real application I use svg file as a stamp, but it’s impossible to load that type of image here, that’s why I loaded here a sample as png (works the same for me, or rather doesn’t work):
goku

Where is the problem? I set opacity as 0.5 and it applies on pdf very randomly (even with full opacity for all stamps) on Chrome (120.0.6099.129 - the same problem with previous version):
image
image

Firefox looks much better for this sample - almost every page refreshing set correct opacity for all three stamps. Sometimes, after a change in code and refreshing page, one of the stamps is full, but it’s rather rare situation.

Any idea what I’m doing wrong?

Best regards and Merry Christmas :christmas_tree:,
Dorota

1 Like

Hello Dorota,

What you are doing is correct. I was able to reproduce this bug and I have added this to our backlog.

Best Regards and Merry Christmas :christmas_tree:,
Darian

2 Likes

Hello,

Apologies for the delay, you have to await setImageData so the API can get all the information before continuing to render.

      await stamp.setImageData('/samples/viewing/viewing/logo.png');

Thank you
Tyler

1 Like

Hello Tyler,

It helped in my case :clap:

Thanks a lot,
Dorota

1 Like