How to highlight text with PDFJS?

chocolate cake picture chocolate cake · Sep 27, 2016 · Viewed 17.8k times · Source

I'm creating an app that shows a PDF file among others. I need to implement a search functionality so that I can search for terms in the pdf file. To display the file I'm using PDFJS.

In the pdfjs library are some examples including the components example that renders a page and you can mark the text (https://github.com/mozilla/pdf.js/tree/master/examples/components).

But when I'm trying to use this code in my app I'm getting the error that PDFJS.DefaultTextLayerFactory() is undefined. I include these three files:

<script src="lib/pdfviewer/pdf.js"></script>
<script src="lib/pdfviewer/pdf.worker.js"></script>
<script src="lib/pdfviewer/pdf_viewer.js"></script>
<script src="lib/pdfviewer/compatibility.js"></script>

What am I doing wrong? Why does PDFJS not know DefaultTextLayerFactory?

Answer

chocolate cake picture chocolate cake · Sep 29, 2016

I found the solution. I forgot to include viewer.js

How to search for terms you can find here