How to add pdf thumbnails to ROX?

Word processors, spreadsheets, presentations, translation, etc.
Message
Author
musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#16 Post by musher0 »

Puppus Dogfellow wrote:musher, [...] is there a way to limit it to just the first page? i think the main purpose of a preview thumbnail is to give a document a unique icon that helps identify its contents and visually differentiate similarly titled files, in which case the cover shot (so to speak) should be enough. [... ]
Now you tell me! :) Ok, guys, version 2 coming up! :)
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#17 Post by musher0 »

Hi, guys.

Best I can do ATM taking into consideration the remarks of both of you. For some
reason, if the # of p. is limited to 1 in pdftops, later, pmnmscale doesn't like ti. So
we have 2 pages minimum. Also, I don't like the wide whitespace at the top and at
the right, and the guilty program should be hunted down later. Finally, if we want to
be able to read the content, IMO, these are not "thumbnails" anymore, simply
"reduced-size images".

Which is why it's not version 2 yet, only version 1a! Sorry. Again, you're welcome
to fiddle with the script to improve it. BFN.

musher0
#!/bin/sh
# Location and title:
# ~/my-applications/bin/pdf2thumb-1a.sh
# Version 1a, for Semme and PuppusDogfellow! ;)
# (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
pnmscale 0.9 $i > "`basename $i | cut -d. -f1`".pnm
# This is barely readable... # Still, for real thumbnails, parameter should be from 0.1 to 0.3.
done
for i in `ls -1 $NOMFICHIER*.pnm`;do
pnmtojpeg $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
Attachments
article001.jpg
I removed about an inch of whitespace at the top and right borders...
Readable... barely. :)
(60.39 KiB) Downloaded 273 times
Last edited by musher0 on Wed 17 Dec 2014, 22:49, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#18 Post by musher0 »

Re-reading the title:
the script produces "thumbnails" NOT integrated to ROX...
Oh well...
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#19 Post by Semme »

To our OP, Dosh.. What's the *target icon size* here, and *where* are you accustomed to viewing such a preview?
>>> Living with the immediacy of death helps you sort out your priorities. It helps you live a life less trivial <<<

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#20 Post by musher0 »

Semme wrote:To our OP, Dosh.. What's the *target icon size* here, and *where* are
you accustomed to viewing such a preview?
Hi Semme.

I'd suggest that Dosh is a WhineDose refugee. WhineDose Explorer has it and a couple of
document organiszers in WhineDose * Seven.

musher0

~~~~~~~
* The OS that Whines if it doesn't get it's Dose (of anti-something). Hey, man, fear
sells! (It's not just sex anymore !) :twisted: .
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#21 Post by musher0 »

Hello again.

If you install this netpbm pet from
http://murga-linux.com/puppy/viewtopic. ... 552#815552
you'll be able to run this:

Code: Select all

#!/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.

BFN.

musher0
Attachments
article001.jpg
Now that's better! (Thanks to pamcut.)
(52.7 KiB) Downloaded 237 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#22 Post by slavvo67 »

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

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#23 Post by musher0 »

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)

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

k2pdfopt

#24 Post by step »

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...
Source code is available.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#25 Post by musher0 »

Hi, step.

No, I didn't know k2pdfopt existed. Thanks for the info.

Best regards.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: How to add pdf thumbnails to ROX?

#26 Post by MochiMoppel »

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:

Code: Select all

#! /bin/sh
exec convert -thumbnail x"$3" "$1"[0] "$2"
That's all :wink:
Attachments
ROX_pdf_thumbnails.png
(32.64 KiB) Downloaded 219 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#27 Post by musher0 »

musher0 wrote:For the record, this java app generates thumbnails as well as bookmarks.
http://flavianopetrocchi.blogspot.ca/
Hello again, people.

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. :)

BFN.

mushero
Attachments
epdfview-example.jpg
(37.06 KiB) Downloaded 184 times
jpdfbookmarks-example.jpg
(56.74 KiB) Downloaded 187 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#28 Post by Semme »

Mochi nailed it! IM's also one of the most flexible and efficient screenshot utilities, bar none.
>>> Living with the immediacy of death helps you sort out your priorities. It helps you live a life less trivial <<<

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#29 Post by slavvo67 »

Hi Mochi,

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

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#30 Post by MochiMoppel »

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 :cry:
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.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#31 Post by musher0 »

Hello, all.

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)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#32 Post by MochiMoppel »

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.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#33 Post by musher0 »

Hello people!

This is the latest and probably last version of the script that I posted on the
previous page.

Code: Select all

#!/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)

Post Reply