How to allow automatic font size change on resize with AnnotationCreateFreeText

WebViewer Version:
8.1.0

Do you have an issue with a specific file(s)?
No

Can you reproduce using one of our samples or online demos?
Yes

Are you using the WebViewer server?
No

Does the issue only happen on certain browsers?
No

Is your issue related to a front-end framework?
Yes

Is your issue related to annotations?
Yes

Please give a brief summary of your issue:

The text annotations do not have the auto font size update functionality when added using AnnotationCreateFreeText tool. But when we add a text annotation programmatically, it allows auto font size update on resize.

Please describe your issue and provide steps to reproduce it:

Same as above, basically I used to use this following piece of code to add text annotations:

annotation = new Annotations.FreeTextAnnotation();
annotation.FontSize = '27pt';
annotation.Font = 'Helvetica';
annotation.TextAlign = 'center';
annotation.TextColor = new window.Annotations.Color('red');
annotation.StrokeThickness = '0pt';
annotation.setContents('Insert text here');

And it used to resize the text annotation’s font size when the select box was resized.

But recently after switching to the AnnotationCreateFreeText tool, which allows to paste the text annotation anywhere on the page after a click, the same resize functionality wasn’t present. It would stick to only one font size even after resizing.

How to accomplish the same here?

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


The behavior you’re experiencing is due to the difference in how FreeText annotations are created. When using the AnnotationCreateFreeText tool, the annotation size is fixed upon creation, and the font size doesn’t automatically adjust when resizing the annotation box. This is different from programmatically created FreeText annotations, which can be configured to adjust the font size dynamically.

Some things you can try:

  • Override the default behavior of the AnnotationCreateFreeText tool by listening to the annotationChanged event. This allows you to adjust the font size based on the annotation’s bounding box size.

  • Programmatically set the FontSize property again after the annotation is resized to ensure it scales with the annotation’s dimensions.

  • Consider implementing a custom tool or modifying the existing tool to include auto-scaling functionality for the font size.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

Alright, I found the issue. I was setting the FontSize to 0pt after adding the text annotation which allowed the dynamic sizing. Did the same after listening for any ‘add’ events for annotations and set the FontSize to 0pt for my new text annotations and it works. Thanks!

1 Like