SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-06-28 18:03:55

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

[Howto]Scanning from the commandline

Yes.  You must think I'm joking.  But it's pretty nice big_smile  So here goes:

1) Connect your scanner (duh!)

2) Run

scanimage -L

to make sure your scanner is detected.  If this step returns "No scanners found", then...I can't help you sad  You'll need to figure that part out on your own (or post here on the forums)

3) Once step 2 shows that your scanner is detected, you're in for the fun part.  Run

scanimage --help

to see what all the options are and set your desired options.  Remember that one of these must be your scanner device (the -d flag).

For example, I use the following set of options:

scanimage -d epkowa --quick-format Letter --resolution=400

4) Take the command line you created in step 3 and append

> test.pnm

and run it.  This will create a file called test.pnm that contains the stuff you scanned.  You can stop right here, but it's kind of a pain to share the file with other people.  If you want to share the file with your peers/coworkers/whatever, proceed to step 5.

5) Run

pnmtops test.pnm > test.ps && pstopdf test.ps

.  This will generate two files: test.ps and test.pdf.

That's it! smile

Enjoy! big_smile


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

Help fund CrunchBang, donate to the project!

#2 2011-06-28 18:32:16

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: [Howto]Scanning from the commandline

thanks! i have a wireless printer/scanner and have not tried using it yet (not made full win > lin transition yet), but i'm sure i will find this useful when i need it smile

Last edited by rhowaldt (2011-06-28 18:32:32)

Offline

#3 2011-06-28 19:29:33

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: [Howto]Scanning from the commandline

wow, that was faster than i thought.

scanning is working. but the scan-quality sucks ass. might be my settings though. some questions for you:

- i tried scanning directly to .pdf; it worked but bad quality
- then i tried scanning to .pnm; it worked but equally bad quality
- then i tried your conversion thing. converting to .ps worked (obviously quality did not improve). convering from .ps to .pdf failed because i don't have pstopdf on my system. tried apt-get but no luck. looked for it through Synaptic but only found 'pstoedit' which should be able but is not making it a .pdf

any ideas?

edit: just tried scanning with -v (verbose) to see a bit more of what's going on. it said it was scanning at 1 bit per pixel. figured that was not so much. so i looked through the scanner-specific settings to see how i could change that. saw this:

--depth 8 [inactive]
        Number of bits per sample, typical values are 1 for "line-art" and 8
        for multibit scans.

however, it says 'inactive', and trying to use the option gives me 'scanimage: attempted to set inactive option depth'. now to figure out how to set an option to 'active'...

edit: SUCCES! ok, turns out the option '--mode' is not inactive, and it was set to 'Lineart'. so, i scanned with '--mode Color' and it worked! quality is not perfect but my test scan of a letter is readable!
here's the command i used (oh yeah i scanned to .tiff so i wouldn't need the conversions):

scanimage --format=tiff -p -v -d epson2 --mode Color > test.tiff

Last edited by rhowaldt (2011-06-28 19:45:17)

Offline

#4 2011-06-28 20:10:32

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Re: [Howto]Scanning from the commandline

pstopdf is (I believe) part of ConTeXt.  The only reason I used it was because ps2pdf gave me pretty bad results (it didn't crop the page properly, which is an absolute must!).  With my scanner, I just used --resolution, but it's a scanner-specific option tongue


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

#5 2011-06-28 21:06:18

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: [Howto]Scanning from the commandline

chaanakya wrote:

pstopdf is (I believe) part of ConTeXt.  The only reason I used it was because ps2pdf gave me pretty bad results (it didn't crop the page properly, which is an absolute must!).  With my scanner, I just used --resolution, but it's a scanner-specific option tongue

i just discovered --resolution, switched it to 300 and got a flawless result. i'll look into scanning to .pdf later (bedtime now!)

thought i'd share something (through which i discovered the --resolution option).
'scanimage --help -d epson2' gives you all the options for the device, but it is a lot and lots of them are inactive. furthermore, i found the command line quite long to type each time i wanted to scan something. so i wrote a bash script for this, simply called 'scan' and taking as 1st argument the destination file.
if the 1st argument is 'help', it prints the options for the device but with the [inactive] ones omitted, which gives a much better overview.

(big thanks to luc here: http://crunchbanglinux.org/forums/topic … ple-lines/)

#!/bin/bash
# use this to scan a file from the command line.
# thanks to chaanakya and luc. go here:
# http://crunchbanglinux.org/forums/topic/13875/howtoscanning-from-the-commandline/
# 'scan FILE.tiff' scans to FILE.tiff.
# 'scan help' shows the available options.
# to do: build some more customization options.
# current options are defaults.

if [ ! $1 ]; then
    echo "provide an output file (example.tiff) or use 'scan help' for options."
    exit
fi
if [ $1 == "help" ]; then
    scanimage --help -d epson2 > temp.txt
    grep -e "failed" temp.txt
    if [ $? = "1" ]; then
        echo "scanner is off."
        rm temp.txt
        exit
    fi
    grep -e "--*" temp.txt | grep -v "inactive"
    rm temp.txt
    exit
fi
echo "now scanning to file \'$1\'"
scanimage --format=tiff -p -v -d epson2 --mode=Color --resolution=300 > $1

i'm planning on expanding it with some more options, but these are the options i'll be using as default. hope someone can find some use for this. chaanakya, again, great how to and really cool to be scanning from the command line!

edit: added a message for when the scanner is turned off. also, i completely forgot to credit chaanakya in my script, so took care of that as well.

Last edited by rhowaldt (2011-06-29 16:55:14)

Offline

#6 2011-11-18 21:13:16

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: [Howto]Scanning from the commandline

editted the script because .tiff makes big files and 300dpi is too much. now scan to pnm and convert to pdf using imagemagick convert.

#!/bin/bash
# use this to scan a file from the command line.
# thanks to chaanakya and luc. go here:
# http://crunchbanglinux.org/forums/topic/13875/howtoscanning-from-the-commandline/
# 'scan FILENAME' scans to FILENAME.pdf.
# 'scan help' shows the available options.
# to do: build some more customization options.
# current options are defaults.

if [ ! $1 ]; then
    echo "provide an output filename or use 'scan help' for options."
    exit 1
fi
if [ $1 == "help" ]; then
    scanimage --help -d epson2 > temp.txt
    grep -e "failed" temp.txt
    if [ $? = "1" ]; then
        echo "scanner is off."
        rm temp.txt
        exit
    fi
    grep -e "--*" temp.txt | grep -v "inactive"
    rm temp.txt
    exit 0
fi
echo "Now scanning to file '$1' in directory "$PWD"."
scanimage --format=pnm -p -v -d epson2 --mode=Color --resolution=100 > $1
convert "$1" "$1.pdf"
rm "$1"
epdfview "$1.pdf"
exit 0

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo