How to set the maximum size of an annotation?

Which product are you using?
PDF.js Express Plus

PDF.js Express Version

Detailed description of issue
How to set the maximum size of a FreeText annotation?

Expected behaviour

Does your issue happen with every document, or just one?

Link to document

Code snippet

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


Hey there!

What do you mean by “maximum size”? Do you mean maximum width and height? Maximum size in bytes? Maximum character count?

Please give a bit more details.



We need to set maximum width and height of annotation.


Please assist, still waiting for a response.


Sorry for the delay - we have some internal APIs that I was trying to make work for your use case but couldn’t figure it out. I think we will add a nice API for this in the future, but for now this should do the trick:

  const MAX_WIDTH = 300;
  const MAX_HEIGHT = 300;

  const oldFunc = instance.Core.Tools.GenericAnnotationCreateTool.prototype.mouseMove;
  instance.Core.Tools.GenericAnnotationCreateTool.prototype.mouseMove = function(...args) {
    oldFunc.apply(this, args)
    if(this.annotation) {
      this.annotation.Width = Math.min(this.annotation.Width, MAX_WIDTH)
      this.annotation.Height = Math.min(this.annotation.Height, MAX_HEIGHT)

This will work for any annotation that requires 2 clicks to make (shapes, lines, etc). For things like freehand annotations it becomes a lot more complicated, so hopefully this is all you need.

Thanks for your patience,