14

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).

gmarmstrong
  • 1,183
  • 1
  • 15
  • 35
  • 1
    Ranger has added this feature since version 1.9.0. See my new answer for details on enabling PDF previews: https://unix.stackexchange.com/a/445138/191530 – gmarmstrong May 21 '18 at 15:34

4 Answers4

16

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;;
gmarmstrong
  • 1,183
  • 1
  • 15
  • 35
10

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.

Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68
  • Works perfectly. – gmarmstrong Dec 01 '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 08 '18 at 16:00
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://".

Hexdump
  • 126
  • 4
1

I modified the code this way to make it work:

pdftoppm -jpeg -singlefile "$path" "$cached" && mv "$cached.jpg" "$cached" && exit 6 || exit 1;;
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Alessandro
  • 21
  • 1
  • Please post this as a comment on https://unix.stackexchange.com/a/408276/191530 and clarify what change you made and why. – gmarmstrong May 16 '18 at 10:54