#!/bin/sh
# Location and title:
# ~/my-applications/bin/pdf2thumb-1b.sh
# (c) musher0, 2014-12-17
####
# set -xv
dirpath=${@%/*}
NOMFICHIER="`basename "$1" | cut -d. -f1`"
pdftops -f 1 -l 2 "$@"
cd $dirpath
pstopnm -xsize=700 -ysize=900 -portrait $NOMFICHIER.ps
# -dpi=300, no.
# These little pnm* executables are pretty fussy, so
# we have to take the winding road.
for i in `ls -1 $NOMFICHIER*.ppm`;do
pamscale 0.9 $i > "`basename $i | cut -d. -f1`".pnm
# This is barely readable...
# Still, for real thumbnails, parameter can be from 0.1 to 0.3
done
for i in `ls -1 $NOMFICHIER*.pnm`;do
pamcut -top=150 -right=500 $i > "`basename $i | cut -d. -f1`".pmm
done
for i in `ls -1 $NOMFICHIER*.pmm`;do
pamtojpeg2k $i > "`basename $i | cut -d. -f1`".jpg
done
wait
rm -f *.p?m
rm -f *.ps
mtpaint -v "$NOMFICHIER"00?.jpg
# defaultimageviewer "$NOMFICHIER"00?.jpg
# set +xv
####
# Final note.
# Usage from cli:
# pdf2thumb.sh <nameof>.pdf
with this result (see pic). You'll notice that this new script uses pamscale, pamcut and
pamtojpeg2k from the recent netpbm-10.67 suite. These newer utilities allow us to get
a much better balanced page.
Final note: the resulting jpg image (of the script process) needs to be loaded and
saved in mtpaint before it can be shown proprely in gpicview or gqview.
Imagemagick can create a thumb.png easily. Just how to script to attach it as an icon instead of drag and drop. file below is the file name of pdf. [0] represents page 1 of the pdf. thumb.png is the thumbnail.
slavvo67 wrote:Imagemagick can create a thumb.png easily. Just how to script to attach it as an icon instead of drag and drop. file below is the file name of pdf. [0] represents page 1 of the pdf. thumb.png is the thumbnail.
convert -thumbnail x80 file.pdf[0] thumb.png
Got an example picture?
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Hey Musher0, the image manipulation in your script seems to lead towards the capabilities of k2pdfopt, are you aware of it? http://www.willus.com/k2pdfopt/
It's a kindle tool but
k2pdf homepage wrote:It can also be used as a general PDF copying/cropping/re-sizing/OCR-ing manipulation tool. It can generate native or bitmapped PDF output...
dosh2684 wrote:i'd like to know if there is in any way for me to view thumbnails for all documents namely pdfs texts docs...
For all documents? Well, let's start with PDFs.
slavvo67 suggests Imagemagick, which probably is your best choice for command line image manipulation:
slavvo67 wrote:Imagemagick can create a thumb.png easily....
convert -thumbnail x80 file.pdf[0] thumb.png
Now let's put this to use and create thumbnails for ROX:
Step 1: Create a folder /root/.config/rox.sourceforge.net/MIME-thumb
Step 2: In this folder create a script with name application_pdf:
It's also one of the best PDF readers out there, except it's not advertised as such.
As opposed to Puppy's epdfview, it has no problem displaying images embedded
in the pdf file.You need to have a java JRE installed to run it, though.
@MochiMoppei : Many thanks for the handy ImageMagick one-liner.
Suppose I don't want to include the name when executing the script. So, maybe I want to execute like I had it but pass the icon to ROX. Is there another way? Something, let's say, similar to my example posted above but taking that png and just passing it to the file in rox as an icon? I'm guessing that's where the $2 comes into play in your script.
This way, you could batch convert a whole directory.
slavvo67 wrote:Suppose I don't want to include the name when executing the script. So, maybe I want to execute like I had it but pass the icon to ROX. Is there another way?
I'm afraid I have no idea what you mean
This way, you could batch convert a whole directory.
ROX always batch converts the whole directory when you switch to thumbnail view. Please keep in mind that the script is run by ROX, so there is nothing for you to execute.
Now we know that the net-pbm package (the pnm/pam execs) does it to a point, that
convert command from ImageMagick does it. But Just to round up our horses on the
subject, does anybody know a way of creating jpg or png thumbnails of a pdf file
using the ghostscript included in most Puppies?
Thanks in advance.
musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
musher0 wrote:Now we know that the net-pbm package (the pnm/pam execs) does it to a point
No, we don't know that. Or did you manage to add pdf thumbnails to ROX?
does anybody know a way of creating jpg or png thumbnails of a pdf file
using the ghostscript included in most Puppies?
Yes, it's possible. Another and much easier option is to use pdftoppm, also included in most Puppies. But this will not help the OP. The point is that none of them produces png thumbnails in a format ROX is willing to use. ROX seems to ignore png files which don't contain metadata. IM is the only application I found that creates files which conform with ROX's picky format requirement.
#!/bin/sh
# Location and title: # ~/my-applications/bin/pdf2thumb-1a.sh
# Using apps from the netpbm kit.
# (c) musher0, 2014-12-17 to 19.
# Usage from cli: # pdf2thumb-1a.sh name_of.pdf
####
# set -xv # for debugging
# Vars
dirpath=${@%/*}
NOMFICHIER="`basename "$1" | cut -d. -f1`"
# Process
# We convert to ps
pdftops -f 1 -l 1 "$@"
cd $dirpath # because little netpbm execs work only with filename.
# Once more, to pnm
pstopnm -xsize=700 -ysize=900 -portrait $NOMFICHIER.ps
# Size parameters necessary for utilities below to work as expected.
# Specifying -dpi=300 seems to mess up things. So, no.
# The next little pnm* executables are pretty fussy, so
# we have to take the winding road.
# We re-scale
for i in `ls -1 $NOMFICHIER*.ppm`;do
pamscale 0.7 $i > "`basename $i | cut -d. -f1`".pnm
# Result is barely readable...
# Still, for real thumbnails, parameter should be explored from 0.1 to 0.3
# to get a +/- 48x48 pixel size. If too small, resulting pnm file is invalid?
# Got errors here reporting an empty file for pamcut.
done
# We remove unwanted white space in borders.
for i in `ls -1 $NOMFICHIER*.pnm`;do
pamcut -top=100 -right=400 $i > "`basename $i | cut -d. -f1`".pmm
done
# Convenient dummy extension for tmp file. Erased at end.
# We have to remember that picture size is changed by pstopnm,
# then pamscale, then pamcut. All contribute to end result.
# Final conversion, to jpg
for i in `ls -1 $NOMFICHIER*.pmm`;do
pamtojpeg2k $i > "`basename $i | cut -d. -f1`".jpg
done
wait # until everything gets processed properly.
# Cleanup
rm -f *.p?m
rm -f *.ps
# Display
mtpaint -v "$NOMFICHIER"00?.jpg # Image should be saved in mtpaint or
# defaultimageviewer "$NOMFICHIER"00?.jpg # won't load it.
# set +xv # We turn debuggging off.
It doesn't create real thumbnails, but the proportions are good. Who knows, someone
may find another use for it. Which is why I've included lots of comments that sum up
my experience.
BFN.
musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)