11

How can I preview PDFs as images in ranger? By default it uses pdftotext (in the scope.sh preview configuration file), but I would like to use pdfimages, pdftoppm, or another graphical solution instead.

The ArchWiki suggests a method using pdftoppm, but it appears out of date (it does not function as-is, and does not follow the structure of surrounding code).

| improve this question | | | | |
7
+100

This works in ranger-stable 1.8.1:

pdf)
        try pdftoppm -jpeg -singlefile "$path" "${cached//.jpg}" && exit 6 || exit 1;;

enter image description here

I also had to create ~/.cache/ranger on my system manually.

| improve this answer | | | | |
  • Works perfectly. – gmarmstrong Dec 1 '17 at 21:44
  • 1
    That doesn't work for me (ranger 1.8.1 on ubuntu), I had to modified the string substitution a bit to make it work. try pdftoppm -jpeg -singlefile "$path" "${cached%.*}" && exit 6 || exit 1;; I guess it is something with shell but I am not an expert on that. – Tg. Jul 8 '18 at 16:00
7

Ranger supports this (disabled by default) since v1.9.0 (see commit ab8fd9e). To enable this, update your scope.sh to the latest version. Note that this will overwrite your previewing configuration file:

ranger --copy-config=scope

Then find and uncomment the following in ~/.config/ranger/scope.sh:

# application/pdf)
#     pdftoppm -f 1 -l 1 \
#              -scale-to-x 1920 \
#              -scale-to-y -1 \
#              -singlefile \
#              -jpeg -tiffcompression jpeg \
#              -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \
#         && exit 6 || exit 1;;
| improve this answer | | | | |
  • I think you'll also need to comment out the other pdftotext configuration in scope.sh. – gmarmstrong Jun 3 '18 at 17:16
  • 1
    Worked for me on macos. I did not have to comment out pdftotext or modify scope.sh in any other way. – Alexander Von Moll Aug 9 '18 at 15:33
  • Yep, that's right. The pdftotext code will only be used if image previews are disabled. – gmarmstrong Jan 30 '19 at 17:01
2

You could try FIM ( http://www.nongnu.org/fbi-improved/#download ). It comes with fimgs which allows to view pdf in the console.

On my Arch i had to compile it myself and start it with FBFONT set to "fim://".

| improve this answer | | | | |
1

I modified the code this way to make it work:

pdftoppm -jpeg -singlefile "$path" "$cached" && mv "$cached.jpg" "$cached" && exit 6 || exit 1;;
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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