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

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:

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