Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there any way I can get the word count of a PDF document that I'm viewing in Evince, Ubuntu's default pdf viewer? I'm able to convert the documents to text files and get the word count from the terminal, but I'd quite like to be able to quickly get at them without having to use the terminal. Is there any plugin that can do this, or is it already built in and I'm just missing it?

P.S. I'd prefer not to change my viewer as Evince is the default PDF viewer in Ubuntu, and I'd quite like to do as much as possible using the default applications since a lot of them, Evince included, are really nice.

share|improve this question
add comment

5 Answers 5

You can do this via command line:

pdftotext filename.pdf - | tr -d '.' | wc -w
share|improve this answer
    
Thanks, but as I said in the question, I'd rather not have to use the command line for this sort of thing. –  Chris Wilson Nov 8 '10 at 19:24
1  
@Chris Try to integrate system("<command above>") in the evince code then. –  Gödel Nov 8 '10 at 19:57
add comment

How about a quick bash script requiring zenity and evince. When called without an argument, it'll give you a dialogue box so you can choose a file. When called with an argument (or after said dialogue box), it'll both open the file in evince and give you a dialogue box with a word count.

In other words, copy the following into a text file, called evince-word-count.sh or something, save it somewhere in your path (e.g., ~/bin/), make it executable (either through Nautilus's right click and properties or with chmod +x ~/bin/evince-word-count.sh),

#!/bin/bash
if [ "$#" -gt "0" ] ; then
    filename="$1"
else
    filename="$(zenity --file-selection)"
fi
evince "$filename" &
zenity --info --text "This PDF has $(pdftotext "$filename" - | tr -d '.' | wc -w) words"
exit 0

Now, right click on some on some PDF in nautilus, choose "Open with..." and then have it open with evince-word-count.sh. Now, when you open a PDF, it'll both open in evince, and give you a word count.

alt text

share|improve this answer
    
You could put this file in /home/$USER/.local/share/nautilus/scripts/ which makes it available from right-click in Nautilus (Ubuntu vanilla file mananger). –  Daniel Holm May 2 at 12:23
add comment
up vote 6 down vote accepted

A response from Olaf Leidinger on the Evince mailing list:

I think such a feature is better suited for document editors, as they have more information on the document as a plain viewer and counting words is trivial. Take a PDF file as an example. What you see as text might actually be some kind of vector graphic shape. Even if the text is contained as such in the PDF file, those words you see might be composed of multiple "draw text at position (y,x)"-commands -- e.g. in case of umlauts or end of line. So a single word might count as multiple words. Therefore I think it might be hard to implement such a feature reliably. Have a look at pdftotext to see what I mean.
share|improve this answer
add comment

I don't believe that is possible (well it's technically possible but hasn't been implemented).

You have to remember Evince is a document viewer and a word count is a feature more usually required in an editor (yes I know this isn't always the case).

You might like to contact the Evince developers and ask if they would have any interest in implementing this feature.

share|improve this answer
1  
Thanks. I've contacted them and I'll keep the question open until I get a definitive response. –  Chris Wilson Nov 8 '10 at 19:25
    
When you hear back, feel free to effectively answer your own question :) –  8128 Nov 8 '10 at 19:32
add comment

As far as I know you can't, but that would be a very good addition if you ask me.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.