reddit / emacs

Is it possible to search text into OCRed PDFs? How?

IvanCyb · 2022-01-29 15:00
Greetings, I’m looking for a good App for knowledge management. I’ve seen many tutorials of Org-Mode and Emacs, and maybe it worths a try. But because I work with many academic researches, I collect lots of PDFs and I need to find text inside of them. Is it possible with Mode and Emacs? How? Thank you!
franburstall · 2022-01-29 15:30
The excellent `pdf-tools` package enables viewing and search of pdf documents.
IvanCyb · 2022-01-29 15:39
Thank you for your reply! I had a look at the website and the demo video. Just another question: can I search for a string of text across ALL the PDFs I've stored somewhere? Can I use booleans?
franburstall · 2022-01-29 17:32
> Just another question: can I search for a string of text across ALL the PDFs I've stored somewhere? Sorry: I do not know how to do that.
pinoaffe · 2022-01-29 18:07
Pdf-tools doesnt support searching through several pdfs at once, you can use the commandline tool pdfgrep (see https://pdfgrep.org ) to do that I dont know what you mean by booleans
intelligent_cat · 2022-01-29 18:57
I use Recoll and helm-recoll.
MangyCanine · 2022-01-29 21:18
Pdfgrep is the way to go, although one has to to know regular expressions. Boolean OR operations, such as “apple or banana”, are pretty simple (note: I gave an example in English — the actual regular expression appears different). Boolean AND operations are messy as you have to write something like, “apple followed by banana or banana followed by apple”. The emacs interface can be found here: https://github.com/jeremy-compostella/pdfgrep (sorry, I’m too lazy to see if someone has created a package for this). Edit: if pdfgrep is compiled with pcre, I think you can then do simpler boolean AND operations, as shown here: https://stackoverflow.com/a/10827606 This works: (?=.*apple)(?=.*banana).* or this, if you need to match words only: (?=.*\bapple\b)(?=.*\bbanana\b).* However, the `-P` option must be passed to pdfgrep. Also note that you can't use `^` in the above as that will oddly cause the match to fail.
__karlota__ · 2022-01-29 21:46
You can use the [rg.el](https://github.com/dajva/rg.el) and change the executable to use the [ripgrep-all](https://github.com/phiresky/ripgrep-all). For example: (use-package rg :config (setq rg-executable (executable-find "rga")))
oldjawbone · 2022-01-29 21:46
I use emacs for a lot of things, but not for multiple PDFs. I just haven't found it conducive to it. 'pdf-tools' includes a function called 'pdf-occur-search' that can query multiple PDFs. But there isn't an interactive function for doing that out of the box, as far as I know. You'd have to write your own, something that uses the form: `(pdf-occur-search '("list" "of" "pdfs") "string")` Even so, using that function for "ALL" your pdfs would be pretty memory/cpu intensive, I would think. Long story short, I use Devonthink for searching through my PDFs.
_viz_ · 2022-01-30 05:16
> Just another question: can I search for a string of text across ALL the PDFs I've stored somewhere? Yes. Mark the files you need in dired and invoke M-x pdf-occur-dired-do-search. Or you can create a virtual pdf, and use M-s o.
IvanCyb · 2022-01-30 17:35
Agreed: I think it would too much CPU and memory intensive. I also use DevonThink: I may stick with it for my PDFs and other documents, and use a lighter and frictionless App for my note taking and my Second Brain.
IvanCyb · 2022-01-30 17:36
I mean something like searching for all the PDFs that contain "text1" AND "text2", or "text1" OR "text2". Something like this.
IvanCyb · 2022-01-30 17:37
Ok I'll have a look at pdfgrep. Thank you for your reply
IvanCyb · 2022-01-30 17:38
Thank you for your reply. Diving into code is something that scares me, but I'll have a look as well :-D