Articles in this section
Category / Section

How to Highlight Text with its Bounds in Angular PDF Viewer?

2 mins read

This article demonstrates how to programmatically highlight text with its bounds when searching for specific text in Angular PDF viewer. The process includes searching for the target text within the document, extracting its position and dimensions, and then overlaying a highlight on the identified text.

Solution:

To programmatically highlight text with its bounds when searching for specific text in PDF viewer, the textSearchHighlight event is used to obtain the bounds of the text, and then the addAnnotation method is used to highlight it.

Code Snippets:

app.component.html
<div>
      <ejs-pdfviewer
        #pdfviewer
        id="pdfViewer"
        [documentPath]="document"
        [resourceUrl]="resource"
        (textSearchHighlight)="textsearchhighlight($event)"
        style="height:640px;display:block"
      ></ejs-pdfviewer>
    </div>
app.component.ts
public textsearchhighlight(e: any): void {
    this.pdfviewerControl.annotation.addAnnotation('Highlight', {
      bounds: [
        {
          x: e.bounds.left,
          y: e.bounds.top,
          width: e.bounds.width,
          height: e.bounds.height,
        },
      ],
      pageNumber: 1,
    } as HighlightSettings);
  }
Sample Link:

You can find the full sample in our GitHub repository.

Conclusion:

I hope you enjoyed learning about how to highlight text with its bounds in Angular PDF Viewer.

You can refer to Angular PDF Viewer feature tour page to know about its other groundbreaking feature representations and documentation , and how to quickly get started for configuration specifications.

You can also explore our Angular PDF Viewer Example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied