switchToAutoFontSize does not work

Product: Apryse PDFTron

Product Version: 10.8.0

Hello, I want the text I put in the freetext annotations to be synamically sized to adapt to the annotation box size.

I fount a function called switchToAutoFontSize() in the API documentation under FreeTextAnnotation.

But the problem is it does not work, rather it hampers other methods and member of the class. For example settinf the fill colour of the annotation fails.

i am using the code as given below, which is exactly similar to the code given in the documentation.

WebViewer(...)
 .then(instance => {
   const { documentViewer, annotationManager, Annotations } = instance.Core;

   documentViewer.addEventListener('annotationsLoaded', () => {
     const annotList = annotationManager.getAnnotationsList();
     annotList.forEach(annot => {
       if (annot instanceof Annotations.FreeTextAnnotation) {
         annot.switchToAutoFontSize();
       }
     });
   });
 });

Hi there,

Thank you for reaching out to WebViewer forums,

It looks like you need to redraw the annotation after setting the auto font size, i.e.

  documentViewer.addEventListener('annotationsLoaded', () => {
    const annotList = annotationManager.getAnnotationsList();
    annotList.forEach(annot => {
      if (annot instanceof Annotations.FreeTextAnnotation) {
        annot.switchToAutoFontSize();
        annotationManager.redrawAnnotation(annot); // redraw the annotation
      }
    });
  });

Using the above and loading the attached document (has 2 free-text annotations)
demo-annotated.pdf (356.6 KB)

The free-text annotation’s font are auto sized to fit the container using the same code, and you should be able to also set the fill color as well:

Best regards,
Kevin Kim

Hello Kevin,

Thank you for replying.
It is still not working for me.
I noticed the error “TypeError: annot.switchToAutoFontSize is not a function” in the browser console.

Thanks,
Subhrajyoti

Hi there,

That indicates that the annotList that you are getting does not contain free-texts, do you have a sample PDF that you are loading? Does the PDF I provided above work for you?

Best regards,
Kevin Kim

Hello Kevin,

here is the pdf I was using.
sample.pdf (3.0 KB)
I had tried the pdf you provided, still I got the same error.

Also, I did check if the annotation object was instance of a FreeTextAnnotation as follows.

documentViewer.addEventListener('annotationsLoaded', () => {
        const annotList = annotationManager.getAnnotationsList();
        annotList.forEach(annot => {
          if (annot instanceof Annotations.FreeTextAnnotation) {
            console.log(annot);
            annot.switchToAutoFontSize();
            annotationManager.redrawAnnotation(annot); // redraw the annotation
          }
        });
      });

Here is the result of the Console.log.
image

Thank you,
Subhrajyoti

Hi there,

The provided sample.pdf document has no annotations:

Using the same document I provided, please see the following video:
81760.mov

Please try this snippet in our showcase and see if you get the same expected results: https://showcase.apryse.com/

Best regards,
Kevin Kim

Hello Kevin,

I tried the showcase and it worked fine.

But when I tried the same thing with my application I get the following error.

Thanks,
Subhrajyoti

Hi there,

Could you please confirm if you have the latest version of WebViewer? I.e. all 3 versions match:

If issue persists, can you share a minimal runnable sample project to investigate?

Best regards,
Kevin Kim

Hello Kevin,

I did a mistake, I forgot to copy the static files to public/web-viewer in the react app.
Apologies for this silly mistake. But I think it’s weird when we do have the node_modules.

Thanks,
Subhrajyoti