# How to set the maximum size of an annotation?

**URL:** <https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068>\
**Category:** Technical Support\
**Created:** [October 13, 2021, 1:14pm UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068 "2021-10-13T13:14:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pankaj](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pankaj](https://pdfjs.community/u/pankaj)\
**Post date:** [October 13, 2021, 1:14pm UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068/1 "2021-10-13T13:14:06Z")

</div>

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

**PDF.js Express Version**  
8.0.0

**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**

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [October 13, 2021, 1:14pm UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068/2 "2021-10-13T13:14:10Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

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

Guides:
- [Create rectangle annotations in PDF.js Express - Other examples](https://pdfjs.express/documentation/annotation/create-annotation-rectangle#other-examples)
- [Rich text](https://pdfjs.express/documentation/annotation/rich-text.8)
- [Create highlight annotations in PDF.js Express - Other examples](https://pdfjs.express/documentation/annotation/create-annotation-highlight#other-examples)

APIs:
- [Annotations.FreeTextAnnotation - setRect(rect)](https://pdfjs.express/api/7.0/Annotations.FreeTextAnnotation.html#setRect__anchor)
- [Core.Annotations.FreeTextAnnotation - new FreeTextAnnotation( [intent] [, initializer])](https://pdfjs.express/api/Core.Annotations.FreeTextAnnotation.html#FreeTextAnnotation__anchor)
- [Core.Tools.TextUnderlineCreateTool - setMinimumAnnotationSizeWhenResizing(minimumAnnotationSizeGetterFunction)](https://pdfjs.express/api/Core.Tools.TextUnderlineCreateTool.html#setMinimumAnnotationSizeWhenResizing__anchor)

Forums:
- [How to create custom SelectionModel similar to the default 8 control handles](https://pdfjs.community/t/how-to-create-custom-selectionmodel-similar-to-the-default-8-control-handles/932/1)
- [How to change the default text in FreeTextAnnotation](https://pdfjs.community/t/how-to-change-the-default-text-in-freetextannotation/936/1)
- [How is exportAnnotations() command different from exportAnnotCommand() for exporting annotations?](https://pdfjs.community/t/how-is-exportannotations-command-different-from-exportannotcommand-for-exporting-annotations/879/1)

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [October 18, 2021, 8:13pm UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068/3 "2021-10-18T20:13:50Z")

</div>

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.

Thanks!  
Logan

---

<div class="post-metadata">

**Author:** ![pankaj](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pankaj](https://pdfjs.community/u/pankaj)\
**Post date:** [October 19, 2021, 7:17am UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068/4 "2021-10-19T07:17:40Z")

</div>

Hi,

We need to set maximum width and height of annotation.

Thanks!

---

<div class="post-metadata">

**Author:** ![pankaj](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pankaj](https://pdfjs.community/u/pankaj)\
**Post date:** [October 29, 2021, 12:25pm UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068/5 "2021-10-29T12:25:25Z")

</div>

Please assist, still waiting for a response.

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [October 29, 2021, 2:57pm UTC](https://pdfjs.community/t/how-to-set-the-maximum-size-of-an-annotation/1068/6 "2021-10-29T14:57:57Z")

</div>

Hey!

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:

```javascript
  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,  
Logan
