Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to search some text in a PDF file. For example, where is the word "go to" in my PDF? If you find it, what page is there?

I find this command line :

 find /TEMP -name 'manu.pdf' -exec pdftotext {} - \; | grep "go to"

It result some elements.

I would like to get the page number of my result.

Do you know how to retrieve that item?

thx

share|improve this question

migrated from stackoverflow.com Apr 24 '12 at 3:19

This question came from our site for professional and enthusiast programmers.

3 Answers 3

pdfgrep seems to do this. From the man page:

-n, --page-number
Prefix each match with the number of the page where it was found.
share|improve this answer
    
Thank you very much, sorry for this topic, I should have to see this page! –  Seb Gouaille Mar 30 '12 at 8:43
    
Sorry but pdfgrep isn't installed on my server. I install poppler-utils but I can't install pdfgrep. So, I haven't any result –  Seb Gouaille Mar 30 '12 at 10:50
    
Why can't you install pdfgrep ? –  Kai Sternad Mar 30 '12 at 10:58
    
On Centos 5.7 and ubuntu 9.10 : apt-get (or yum) install pdfgrep : No package pdfgrep available. I download the 1.3.0.tar.gz, unzip, ./configure : configure: error: Package requirements (poppler-cpp) were not met: No package 'poppler-cpp' found. I can do nothing –  Seb Gouaille Mar 30 '12 at 12:09
    
Pdfgrep is available from Ubuntu 10.10 on. I've just successfully installed it in a Ubuntu 11 VM –  Kai Sternad Mar 30 '12 at 16:27

As per default, pdftotext does insert form feed characters (0xC) between pages. You can count them up to the appearance of the word you search for.

Another way is to use the bbox option:

 Generate an XHTML file containing bounding box information for each word in the file.

Here, every word is enclosed in a page container. So you can take the index+1 of the page your word is in as page number

share|improve this answer
    
Do you have an example to get it? –  Seb Gouaille Mar 30 '12 at 12:21

Recoll can search PDF documents. It has a command line mode, but the GUI will be more helpful in detailing where the matches occur, and it will let you click open the document at the right position.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.