stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
473 stars 181 forks source link

Search : is it possible to have an index of all results #460

Closed f-malet closed 2 years ago

f-malet commented 4 years ago

Hello,

I would like to search a term in the PDF and I would like to have an index of each result with a context (for example the sentence around the search term) and a link to the page. I try to use the 2 events (updateFindMatchesCount) and (updateFindState) but I don't see any information about these informations. Is it currently possible to do that with the existing library and if yes, how ?

Thanks for your work ;)

stephanrauh commented 4 years ago

@timvandermeij I include you in the loop because I'm fascinated by what people do with our libraries - and maybe this kind of stuff gives you new ideas how to improve pdf.js. Oh, and if you've got an answer to the question, don't hesitate to tell us. :)

@f-malet You question rings a bell. I believe I've seen such an option some time ago, but I'm not sure, and when I started digging into my sourcecode (and the sourcecode of the pdf.js team), I didn't find it.

So there are two or three options:

timvandermeij commented 4 years ago

PDF.js does not provide this functionality, I think mainly because we don't display such information in the viewer. However, if there are improvements that can be made on the PDF.js side in terms of the API or the information in the event, we're always open to suggestions if that makes third-party implementations easier.

f-malet commented 4 years ago

Thanks you for your answers and your time :).Maybe I'll try the third option but I have to link each extraction result to the page to go to it. I don't know if it is possible. If one day you implement this functionality, tell me, i really appreciate :) Have a good night and thanks again ;)

stephanrauh commented 3 years ago

I've implemented a partial solution. When you've updated to version 9.0.0-alpha.1 (which is yet to be release), you'll notice a new attribute. I don't want to document it because it's not the solution I'd like to offer, so I prefer to be flexible. But you can already see which page contains how many search results.

The problem with delivering a more satisfying solution is that the text layer is rendered both lazily and asynchronously. So it's not possible to return a list of <div> tags - simply because they haven't been rendered yet, and maybe they will never be rendered, depending on what the user does. I've tried to force rendering the text layer, but to no avail. I'm not even sure it's a good idea to do so because rendering the text layer costs a lot of performance.

Be that as it may: it's easy to find the <div> and <span> tags that already have been rendered. Just look for the CSS class .highlight.

stephanrauh commented 2 years ago

I think I've managed to implement a demo that might help developers. So let's close the ticket.

parultrantor commented 5 months ago

publish the list of search results with `(updateFindMatchesCount…

Hey @stephanrauh Great repo! Can you please point me to the demo you have created I also want to implement something of this sort.

Thank you :)

stephanrauh commented 5 months ago

Oh. That's a long time ago. I can hardly remember, but I think you're looking for (updateFindMatchesCount).