w3m
( w3m-img
) can display inline images. __. On __jfbterm. If you think that, recently it seems that it can also be displayed on fbterm. Thank you.
ranger
can preview images with the help of such w3m
. You can also preview pdf and video files by tweaking the configuration file a little.
ranger
can display PDF, so we can do it. First, turn the PDF into an image.
How does ranger
preview the PDF? The answer can be found in ** $ HOME/.config/ranger/scope.sh **. If you don't have such a file, do ranger --copy-config = all
. Around line 162 is:
:$HOME/.config/ranger/scope.sh (162)
## PDF
application/pdf)
pdftoppm -f 1 -l 1 \
...
I see, it seems to use pdftoppm
to convert PDF to image. Detailed usage can be obtained with man pdftoppm
. Please get it.
PDF Command to convert to image
$ pdftoppm -png PDF file name Image file prefix
Since w3m
can display inline images, write HTML for w3m
. But be aware that he can't read css. HTML 4.01 Transitional Let's write below.
w3m For HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Hogehoge.pdf</TITLE>
</HEAD>
<BODY>
<CENTER>
<DIV><IMG SRC="path/to/image/page-01.png " WIDTH="80%"></DIV>
<DIV><IMG SRC="path/to/image/page-02.png " WIDTH="80%"></DIV>
...
</CENTER>
</BODY>
</HTML>
And if you read this HTML with w3m
, you can see the PDF converted to an image.
We managed to see the PDF. However, doing this every time you want to view the PDF is very tedious. Most of what we can do can be done with computers.
Write the following shell script. The file name is ** pdfm.sh ** from PDF-wo-Miru (view PDF).
pdfm.sh
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` pdf-file"
exit 1
fi
TEMPDIR=`mktemp -d`
TEMPBASE="$TEMPDIR/pdfm"
TEMPHTML=`tempfile -s.html`
pdftoppm -png $1 $TEMPBASE
cat << EOF > $TEMPHTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>$1</TITLE>
</HEAD>
<BODY>
<CENTER>
EOF
find $TEMPDIR/*.png | sort | while read line
do
echo "<DIV><IMG SRC=\"$line\" WIDTH=\"80%\"></DIV>" >> $TEMPHTML
done
cat << EOF >> $TEMPHTML
</CENTER>
</BODY>
</HTML>
EOF
w3m $TEMPHTML
rm -rf $TEMPHTML $TEMPDIR
When you're done, run make pdfm
and put the generated ** pdfm ** around ** $ HOME/bin/**.
The end.
Recommended Posts