How to load pdf files from url using react-pdf-viewer or some other library with search button?

1.2k Views Asked by At

I am trying to load pdf from url using react-pdf-viewer library. I need a search button therefore I use this library. Is it possible to load pdf from url in this library? Or should I use any other library?

My current implementation is

const pdfFile = require("../assets/pdf/mypdf.pdf");

return (
        <Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js">
          <div style={{ height: "720px", marginTop: "120px" }}>
            <Viewer fileUrl={pdfFile} plugins={[defaultLayoutPluginInstance]} />
          </div>
        </Worker>
      );
1

There are 1 best solutions below

1
On

Most react react-pdf-viewer libraries like this syncfusion one according to its demo is a hybrid where search can be at two levels both internal and external, here we can see the two text layers subject to a search and the result by search in the browser.

enter image description here

You specify one that appears to be similar based on PDF.js which should have an internal spyglass https://codesandbox.io/s/react-pdf-viewer-sample-yc8ut?file=/public/pdf-open-parameters.pdf

enter image description here

So most react js based libraries should offer one or the other, if not both. (but beware it's not always the real pdf which is in the back end)

enter image description here

Here is a windows binary PDF client viewer with same URL enter image description here