LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-26-2016, 08:36 PM   #1
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Rep: Reputation: Disabled
Scanning multi-page document automation in Bash


I'm working on scanning a large number of multi-page documents and converting them to PDF files. My current method is:
Code:
scanimage > A.tiff --format=tiff --mode Gray --resolution 200dpi #this step is repeated, incrementing the A alphabetically, for as many pages as are in the file- usually about 10 or 12.

convert *.tiff 1.pdf

gs -dNOPAUSE -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -sOutputFile=name.pdf 1.pdf

rm *.tiff 1.pdf
Is there a way to create a script that will ask for the number of pages and file name, then automate this process, only requiring me to turn the pages of the document?

Many thanks,
Kytsuine

Last edited by Kytsuine; 04-27-2016 at 02:50 PM.
 
Old 04-27-2016, 04:56 AM   #2
translator1111
Member
 
Registered: Jun 2010
Location: Slovakia
Distribution: Debian 8, Ubuntu 10.04 and 12.04; SLAX 6.0; ConnochaetOS 0.9.; LFS; Natty chip: VT1708S
Posts: 93
Blog Entries: 2

Rep: Reputation: 7
Dear Kytsuine,
does this code help you to create your automation?
Code:
#!/bin/bash
EndScanning=true
echo "Please tell me the name of your file"
read FileName
FileName= name
echo "Please tell me how many pages are in the file"
read PagesFile
PagesFile= A

if EndScanning = False then
A=A+1
end if
Regards,
M
 
Old 04-27-2016, 06:37 AM   #3
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Possibly? I'll check once I get to the workstation. Does the if section increment the value A, and if so, do I need to change what I use for the file name in the scanimage line so it treats A as a variable and not as a letter?
 
Old 04-27-2016, 07:33 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,834

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
There are lots of ways to write your script. Yes you need to change the scan command to use a variable for the document name as well as the conversion process. Taking the above script up just a notch.

Code:
#!/bin/bash

read -p "Enter Document name " doc
read -p "Enter number of pages to scan " pgs

for (( x=1; x<=$pgs; x++ ))
 do
  read -p "Press Enter to scan page $x " answer
  echo Scanning $doc-$x
  #scanimage command goes here
done
echo "Do conversion here"
convert $doc-*.tiff $doc.pdf
#gs command goes here
...

Last edited by michaelk; 04-27-2016 at 07:44 AM.
 
1 members found this post helpful.
Old 04-27-2016, 02:50 PM   #5
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Michaelk, I'll be testing that as soon as I get back to the workstation (we had a network outage today, but I should be able to test it in about half an hour.) If this works, then thank you very much. Just to check, did I substitute the variables right in the following code I'll be using?
Code:
#!/bin/bash

read -p “Enter Document name “ doc
read -p “Enter Number of Pages to Scan “ pgs

for ((x=1; x<=$pgs; x++))
do
read -p “Press Enter to scan page $x “ answer
echo Scanning $doc-$x
scanimage > $x.tiff --format=tiff --mode=Gray --resolution 200dpi
done
echo “Do conversion here”
convert *.tiff 1.pdf
gs -dNOPAUSE -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -sOutputFile=$doc 1.pdf
...
 
Old 04-27-2016, 03:16 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,834

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
In my script the tiff files would be named doc-1.tiff,doc-2.tiff vs 1.tiff, 2.tiff etc but yours will work Just add another command to delete the old tiff files and 1.pdf files. The ... was supposed to represent the rest of your process and not an actual command.

Last edited by michaelk; 04-27-2016 at 03:19 PM.
 
Old 04-27-2016, 03:30 PM   #7
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Result: After running it, I get the output:

"./scan.sh: 6: ./scan.sh: Syntax error: Bad for loop variable"
 
Old 04-27-2016, 03:34 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,834

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
What linux distribution / version is running on the workstation?
 
Old 04-27-2016, 05:24 PM   #9
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Currently, Kali off a LiveUSB (I didn't have anything else, and the tech guys still can't find the cd with the drivers for Windows, so I'm just doing what I can. I hope to swap her over to Porteus soon.)
 
Old 04-27-2016, 05:24 PM   #10
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
The ... was supposed to represent the rest of your process and not an actual command.
D'oh.
 
Old 04-27-2016, 06:00 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,834

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
I would of expected kali to be running a version of bash that has for loop capabilities. But you can try this:

Code:
x=1
while [ $x -le $pgs ]
do
  read -p “Press Enter to scan page $x “ answer
  echo Scanning $doc-$x
  scanimage > $x.tiff --format=tiff --mode=Gray --resolution 200dpi
  x=$(( $x + 1 ))
done
 
1 members found this post helpful.
Old 04-27-2016, 07:48 PM   #12
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Partial success. I had some trouble with read, which I was able to work around with some Googling, and ended up with the following code.
Code:
 
#!/bin/bash

echo "Type the name you want for the finished file." 
read doc
echo "How many pages are in the file?" 
read pgs
x=1
while [ $x -le $pgs ]
do
	echo "Press any key to scan page $x"
	read answer
	echo Scanning $doc-$x
	scanimage > $x.tiff --format=tiff --mode=Gray --resolution 200dpi
	x=$(( $x + 1 ))
done
echo "Converting now" 
convert *.tiff 1.pdf
gs -lotsastuffthatIdontwanttotype
rm *.tiff 1.pdf
While this works, when scanning documents longer than 9 pages, I end up with pages 10-19 directly after 1, 20-29 directly after 2, and so on. Is there an easy way to fix this?
 
Old 04-27-2016, 08:40 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,834

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
Alphanumeric sorting...
Will make it easy.
Code:
x=1
for y in {a..z}{a..z}
do
   echo "Press enter key to scan page $x"
   read answer
   echo Scanning $doc-$x
   scanimage > $y.tiff --format=tiff --mode=Gray --resolution 200dpi
   x=$(( $x + 1 ))
   if [ $x -gt $pgs ]
   then
     break
   fi
done

Last edited by michaelk; 04-27-2016 at 08:46 PM.
 
1 members found this post helpful.
Old 04-28-2016, 03:28 PM   #14
Kytsuine
LQ Newbie
 
Registered: Sep 2015
Location: Western Kentucky. No, farther west. Farther... there you go.
Distribution: Linux Mint 17.2 Cinnamon, Kali Linux, Arch (still debugging USB install...)
Posts: 25

Original Poster
Rep: Reputation: Disabled
Okay, I replaced the while loop with what you had in the newest one, and ended up with a .tiff named {a...z}{a...z}.tiff, which caused me some confusion. It then did not repeat the scan (likely because y was greater than 11, the number of pages) and completed the rest of the script successfully.
 
Old 04-28-2016, 03:37 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,834

Rep: Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798Reputation: 1798
Interesting. The sequence is nothing new so I am not sure why it isn't working. You still running kali?
The for loop should iterate like aa,ab,ac...az,ba,bb,bc and so on.
 
  


Reply

Tags
bash, ghostscript, scanning, terminal


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] scanning makes page huge mark_alfred Linux - Software 16 12-12-2014 09:29 PM
Web page automation - application Gr2600 Programming 6 01-06-2013 12:37 PM
Extracting 1 page from a PDF Document dazdaz General 2 06-16-2012 09:51 AM
Bluetooth, synching, treo750, document scanning, sd card reader, vaio laptop, kubuntu Josef Lauei Linux - Newbie 1 09-30-2008 08:32 AM
Document Automation in Linux??? JaseP Linux - Software 7 04-07-2004 12:23 PM


All times are GMT -5. The time now is 11:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration