pdf text search not working

PDF JS search text

Rate this article

Share this article

Read  PDF JS search text for more information.

PDF.js or pdf.js is a JavaScript library that renders Portable Document Format (PDF) files using the web standards-compliance HTML5 Canvas. The project is led by the Mozilla Foundation after Andreas Gal launched it (initially as an experiment) in 2011.

PDF.js can work as a part of a website or of a browser. Originally created as a Firefox extension, it is now included in Mozilla Firefox since 2012 (version 15) and is enabled by default since 2013 (version 19).

pdf js search text

How to search with pdf.js?

Here is the solution:

var container = document.getElementById('viewerContainer');
var viewer = document.getElementById('viewer');

var pdfViewer = new PDFViewer({ 
   container: container,
   viewer: viewer

$scope.pdfFindController = new PDFFindController({
   pdfViewer: pdfViewer


container.addEventListener('pagesinit', function () {
    pdfViewer.currentScaleValue = 'page-width';                            

PDFJS.getDocument(MY_PATH_TO_THE_PDF).then(function (pdfDocument) {

And for the search

$scope.pdfFindController.executeCommand('find', {
    caseSensitive: false, 
    findPrevious: undefined,
    highlightAll: true, 
    phraseSearch: true, 
    query: "myQuery"

If you don’t want to go through the trouble of coding to set up a PDF search then you can try a PDF search engine instead.

Finding a good cms to host all your pdfs can also be a challenging task. One such good easy to use cms is for pdfs is wix. But the problem here is wix default search does not have the capability to search through pdf files hence you need to setup a separate on site search for wix. This new search should be able to search website wix completely including any pdf files. Another up and coming cms is Squarespace. Squarespace also has the same issue where you will not be able to search through the pdf files and hence need to setup a separate squarespace search. One of the best options for pdf search is Expertrec search.


Create a PDF search engine

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
You may also like