Preview PDF as image in ranger

14,606

Solution 1

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;;

Solution 2

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.

Solution 3

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://".

Solution 4

I modified the code this way to make it work:

pdftoppm -jpeg -singlefile "$path" "$cached" && mv "$cached.jpg" "$cached" && exit 6 || exit 1;;
Share:
14,606

Related videos on Youtube

gmarmstrong
Author by

gmarmstrong

Updated on September 18, 2022

Comments

  • gmarmstrong
    gmarmstrong almost 2 years

    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
    gmarmstrong over 6 years
    Works perfectly.
  • gmarmstrong
    gmarmstrong about 6 years
    Please post this as a comment on unix.stackexchange.com/a/408276/191530 and clarify what change you made and why.
  • gmarmstrong
    gmarmstrong about 6 years
    I think you'll also need to comment out the other pdftotext configuration in scope.sh.
  • Tg.
    Tg. almost 6 years
    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.
  • Alexander Von Moll
    Alexander Von Moll almost 6 years
    Worked for me on macos. I did not have to comment out pdftotext or modify scope.sh in any other way.
  • gmarmstrong
    gmarmstrong over 5 years
    Yep, that's right. The pdftotext code will only be used if image previews are disabled.