I have a large library of PDF documents (papers, lectures, handouts) that I want to be able to quickly navigate through. For that I need thumbnails.

At the same time however, I see that the ~/.thumbnails folder is piling up with thumbs I don't really need. Deleting thumbnail junk without removing the important thumbs is impossible. If I were to delete them, I'd have to go to each and every folder with important PDF documents and let the thumbnail cache regenerate.

I would love to be able to automate this process. Is there any way I can tell nautilus to pre-cache the thumbs for a set of given directories?

Note: I did find a set of bash scripts that appear to do this for pictures and videos, but not for any other documents. Maybe someone more experienced with scripting might be able to adjust these for PDF documents or at least point me in the right direction on what I'd have to modify for this to work with PDF documents as well.

Edit:

The response to this question has been quite overwhelming. Let me first thank everyone who participated in solving this. The question, its answers and all the discussion around it are a great example of how the collaborative effort of many parties can lead to an optimal solution. This is exactly what makes Linux and Open Source so great.

All of the provided answers would deserve the bounty I originally put up for this question. Still, there's only one bounty to award. I owe it to all future readers to choose the answer that solves the problem in the most efficient way. To determine which solution that is, I did a final test run, comparing the three scripts in compatibility, speed and output quality. Here are the results:

Thumbnailer 1, by rosch:

Compatibility: ✔ spaces in file name ; ✔ spaces in directory name ; ✘ freedesktop compliant

Speed: 95 PDFs in 12,6 sec

Quality: stock nautilus quality

Additional Perks: 1.) automatically skips files with preexisting thumbs ; 2.) No additional packages needed

Thumbnailer 2, by Martin Orda:

Compatibility: ✔ spaces in file name ; ✔ spaces in directory name ; ✘ freedesktop compliant

Speed: 95 PDFs in 70,0 sec

Quality: significantly better scaling than the stock images.

Additional Perks: 1.) automatically skips files with preexisting thumbs 2.) compatible with a wide range of image formats besides PDF 3.) platform-independent, does not rely on GNOME-components

Thumbnailer 3, by James Henstridge:

Compatibility: ✔ spaces in file name ; ✔ spaces in directory name ; ✔ freedesktop compliant

Speed: 95 PDFs in 10,8 sec

Quality: stock nautilus quality

Additional Perks: 1.) automatically skips files with preexisting thumbs 2.) compatible with all file formats that are identified by the preinstalled thumbnailers

All three scripts are excellent. Each has its distinct set of advantages and disadvantages. Rosch's solution works out of the box and might be the right choice for users with a minimal installation.

Marcin Kaminski created a very versatile script that works with a variety of file formats and is DE-independent. It excels at thumbnail quality but does so at the expense of speed.

In the end it was James' solution that fit my use case best. It's fast, versatile and offers the options to skip over files with preexisting thumbnails.

Overall winner: James Henstridge

Additional information: All three scripts are fully compatible with nautilus-scripts. You can easily install them following this tutorial.

Edit 2: Updated review with improved script by rosch.