View PDF with fbterm

View PDF with fbterm

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.

sc1.png sc2.png

That means

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

Display an image (PDF)

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.

test.gif

It's a hassle

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/**.


in conclusion

The end.

Recommended Posts

View PDF with fbterm
Output PDF with Django
Output PDF with WeasyPrint
View PDF on Jupyter Notebook
View Python communication with Fiddler
Integrate PDF files with Python
View flask coverage with pytest-cov
View photos taken with LYTRO ILLUM
Convert PDF to image with ImageMagick
Convert from PDF to CSV with pdfplumber
Extract Japanese text from PDF with PDFMiner
Simplify PDF password unlock with python + bat
PDF output with Latex extension in Sphinx
Convert PDF files to PNG files with GIMP