Mikeri's tech-babble

2019-05-11

Fast PDF thumbnail generation

Most of the well known freedesktop.org abiding file managers support thumbnail generation trough the Thumbnail Managing Standard. (My favorite is PCManFM and it is no exception.) However, my PDF documents were not thumbnailed as I did not have Evince installed. I did not want to install Evince with all the Gnome dependencies that would follow as I was (and am) very happy with Okular.

I wrote a simple thumbnailer that uses ImageMagick and it while it does work it has two things that could be better:
- it is slow
- some times it draws white areas around the thumb. I suspect this is because the document contains one or more pages that is bigger than the first page.

After stumbling across this blog post, I wrote a thumbnailer using mutool instead. Because of mupdfs high speed it is blazingly fast and does not create white space around the thumb when there are mixed page sizes.

Install mupdf-tools and put the following in ~/.local/share/thumbnailers/mutool-pdf.thumbnailer to achieve fast PDF thumbnailing:

[Thumbnailer Entry]
  TryExec=mutool
  Exec=mutool draw -w %s -h %s -o %o %i 1
  MimeType=application/pdf;application/x-pdf;image/pdf;


PS, the thumbnailer is also available as a gist.