Preview PDF as image in ranger
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;;
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;;
Related videos on Youtube
gmarmstrong
Updated on September 18, 2022Comments
-
gmarmstrong almost 2 years
How can I preview PDFs as images in ranger? By default it uses
pdftotext
(in thescope.sh
preview configuration file), but I would like to usepdfimages
,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 about 6 yearsRanger has added this feature since version 1.9.0. See my new answer for details on enabling PDF previews: unix.stackexchange.com/a/445138/191530
-
-
gmarmstrong over 6 yearsWorks perfectly.
-
gmarmstrong about 6 yearsPlease post this as a comment on unix.stackexchange.com/a/408276/191530 and clarify what change you made and why.
-
gmarmstrong about 6 yearsI think you'll also need to comment out the other
pdftotext
configuration inscope.sh
. -
Tg. almost 6 yearsThat 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 almost 6 yearsWorked for me on macos. I did not have to comment out
pdftotext
or modifyscope.sh
in any other way. -
gmarmstrong over 5 yearsYep, that's right. The
pdftotext
code will only be used if image previews are disabled.