How to detect text overflow in free text annotation

PDFTron.NET x64
Product Version:

Please give a brief summary of your issue:
I need to detect if all the text in the text annotation will be displayed or if it will be clipped

Please describe your issue and provide steps to reproduce it:
I have TextWidget or FreeText annotation with fixed dimensions. The text in the annotation can change and I need to inform the user that part of the text is not visible in the annotation field because it’s too long.
Is it possible to precisely calculate it, taking the word wrap funcationality of the free text annotation into the account?

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:


The text in the annotation can change and I need to inform the user…

Is this an interactive, or non-interactive use case?

If interactive, what is the viewer/platform/sdk being used for the user interaction?

It’s non-interactive. We generate the annotation on the server in an async process.

Please try our Stamper class, and use the SetAsAnnotation to true.

Though, this creates a RubberStamp annotation. If you like, you can edit it to be a FreeText by post-processing this way. First, to get the Stamp annot after stamping see this post.

That will create the annotation with the size you want, and the appearance you want, however it is the wrong type of annotation. A RubberStamp one instead of a FreeText. So you can just take the size and appearance of the RubberStamp and use it to finish off a new FreeText annotation. This code shows how to swap them around.

// Create FreeText annotation as normal, applying the same colors, font and font size as the Stamper.
FreeText ft = FreeText.Create(doc, stamp_annot.GetBBox());
// ft.SetFont(...)
// ... etc.
ft.Put("AP", stamp_annot.FindObj("AP"));