The pdftotext command which comes as part of the poppler package is useful. Use it as follows. Note the dash (-) which tells it to write to stdout.
pdftotext some_file.pdf - | grep some_word
I don't know if there is a similar program for chm files, though I see there is a package in my distro named html2text. I haven't used it, but maybe it handles chm.
For other miscellaneous formats, including binary, I find the strings command immensely valuable. It comes as part of the binutils package, which is probably installed in all distros.