Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to find font associated to an annotation #11364

Closed
zagoa opened this issue Nov 27, 2019 · 1 comment
Closed

Impossible to find font associated to an annotation #11364

zagoa opened this issue Nov 27, 2019 · 1 comment
Labels

Comments

@zagoa
Copy link

zagoa commented Nov 27, 2019

Configuration:

  • Web browser and its version: Brave 1.0.1
  • Operating system and its version: Ubuntu 18.04
  • PDF.js version: 2.3.200
  • Is a browser extension: no

Steps to reproduce the problem:

  1. Get FreeText annotations from a document
  2. Try to loop over to extract rect
  3. convert the list of rectangle in the viewport and inject them in the TextLayer

What is the expected behavior?
My goal is to make available the selection on annotations. I can handle the position of rectangles, but impossible to find/get through the API the font or the font-size used during the drawing.
The annotation object doesn't contain it.

My code look like something like that

    const page = this.pdfElement.getPageView(pageNumber - 1);
    page.annotationLayer.pdfPage.getAnnotations()
      .then(annotations => {
        annotations
          .filter(annotation => annotation.contents)
          .forEach(annotation => 
            const convertedRect = page.viewport.convertToViewportRectangle(annotation.rect)

            const htmlElement = document.createElement('span');
            htmlElement.innerText = annotation.contents;
            htmlElement.style.left = convertedRect[0] + 'px';
            htmlElement.style.top = convertedRect[1] + 'px';
            htmlElement.style.width = convertedRect[2] + 'px';
            htmlElement.style.height = convertedRect[3] + 'px';
            page.textLayer.textLayerDiv.prepend(htmlElement);
          }
          )
      })

There is somewhere where I can get the font and have a span in the textLayer matching the annotation text?

Thank for your help :)
(PS: there is a font describe in my PDF, when I open it i can find /F: 4 and it's defined)

@Snuffleupagus
Copy link
Collaborator

The font information for a given annotation can be found via the defaultAppearanceData-property, for applicable annotation types, on the annotation-data that's returned by the PDFPageProxy.getAnnotations method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants