# Can fitText be used to set only height? If not, is there an alternative

**URL:** <https://pdfjs.community/t/can-fittext-be-used-to-set-only-height-if-not-is-there-an-alternative/896>\
**Category:** Technical Support\
**Created:** [July 22, 2021, 9:02pm UTC](https://pdfjs.community/t/can-fittext-be-used-to-set-only-height-if-not-is-there-an-alternative/896 "2021-07-22T21:02:48Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [July 29, 2021, 8:07pm UTC](https://pdfjs.community/t/can-fittext-be-used-to-set-only-height-if-not-is-there-an-alternative/896/5 "2021-07-29T20:07:21Z")

</div>

Hi there!

We have an API for this coming in version 8.0 (will be released soon), but for now I found a little trick that should work for you.

The `pageInfo` object you pass in contains the width and height of the document, and the `fitText` function uses that width to know how far over to the right it is allowed to expand before it needs to break to the next line. By altering `pageInfo.width` we can trick the function into breaking into a new line before it actually needs to:

```javascript
const freeTextAnnot = new Annotations.FreeTextAnnotation();
freeTextAnnot.X = 100;
freeTextAnnot.Width = 100;
// ... other annot config

const pageInfo = doc.getPageInfo(pageNumber);
pageInfo.width = freeTextAnnot.X + freeTextAnnot.Width;
freeTextAnnot.fitText(pageInfo, pageMatrix, pageRotation);

```

This code will make sure the freeTextAnnot always maintains the width you set it to.

Let me know this goes!

Thanks,  
Logan

---

_[View the full topic](https://pdfjs.community/t/can-fittext-be-used-to-set-only-height-if-not-is-there-an-alternative/896)._
