{"id":219,"date":"2006-06-07T12:30:09","date_gmt":"2006-06-07T16:30:09","guid":{"rendered":"http:\/\/www.grebfamily.us\/jasongreb.com\/?p=219"},"modified":"2006-06-07T22:40:56","modified_gmt":"2006-06-08T02:40:56","slug":"bash-script-like-paperport","status":"publish","type":"post","link":"http:\/\/blog.jasongreb.com\/?p=219","title":{"rendered":"Bash Script like PaperPort"},"content":{"rendered":"<p>Mac Jones from New Zealand, created this great <a href=\"http:\/\/maconstuff.blogspot.com\/2006\/05\/scan-to-pdf-in-ubuntu-with-beagle.html\">bash script that scans pages<\/a> from your scanner, then turns them into a PDF. Well, I took that script, and improved upon it. Check it out.<\/p>\n<p><!--more--><\/p>\n<p>&#8211; Producer option for your name<br \/>\n&#8211; Output folder, with temp files in \/tmp<br \/>\n&#8211; Device selection (since scanimage picks up my TV tuner as the default scanner), if more than one devices exists<br \/>\n&#8211; Resolution options<br \/>\n&#8211; Page size options (since my default was like post card size on my scanner), including a &#8220;custom size&#8221;<br \/>\n&#8211; Progress bar for scanning (however, does not show &#8220;progress&#8221; at the moment)<br \/>\n&#8211; And an option to restart with a new document<\/p>\n<p>I am not a bash script expert, and I just whipped this together. There may be better ways to do things&#8230; just let me know<\/p>\n<blockquote><p>\n#!\/bin\/sh<\/p>\n<p>#scan to pdf with metadata, by Mac Jones, New Zealand<br \/>\n#http:\/\/maconstuff.blogspot.com\/<\/p>\n<p>producer=&#8221;Your Name&#8221; # If you&#8217;d like it inputed into the PDF, otherwise, rem the line<br \/>\noutputfolder=&#8221;\/home\/user\/ScannedDocuments\/&#8221; # Pre-fix for last outputted file<\/p>\n<p>#scan a batch<\/p>\n<p>#select a scanner if more than one exists, or just uncomment the next line, and comment the rest<br \/>\n#scannerdevice=&#8221;-d DEVICE&#8221;<\/p>\n<p>devices=`scanimage -L | awk &#8216;{print $2}&#8217; | cut -c 2-50 | tr -d =\\&#8217;=`<br \/>\ndevicenum=`echo $devices | wc -w`<br \/>\nif [ &#8220;$devicenum&#8221; -gt 1 ]; then<br \/>\ndevices=`echo $devices | sed -e &#8216;s\/ \/ FALSE \/g&#8217;`<br \/>\nscannerdevice=`zenity &#8211;list &#8211;title &#8220;Device?&#8221; &#8211;radiolist &#8211;column &#8220;-&#8221; &#8211;column &#8220;Device&#8221; TRUE $devices`<br \/>\nelse<br \/>\nscannerdevice=&#8221;$devices&#8221;<br \/>\nfi<\/p>\n<p>restart=1<br \/>\nuntil [ &#8220;$restart&#8221; -eq 0 ]; do<\/p>\n<p>#ask for the resolution<br \/>\nresolution=`zenity &#8211;list &#8211;title &#8220;Resolution?&#8221; &#8211;radiolist &#8211;column &#8220;-&#8221; &#8211;column &#8220;Resolution&#8221; FALSE 100 TRUE 150 FALSE 300 FALSE 350 FALSE 600`<\/p>\n<p>#ask for the page size, mm on most scanners, yours may differ, run scanimage &#8211;help -d DEVICE<br \/>\nqpagesize=`zenity &#8211;list &#8211;title &#8220;Page Size?&#8221; &#8211;radiolist &#8211;column &#8220;-&#8221; &#8211;column &#8220;Page Size&#8221; TRUE Letter FALSE Legal FALSE A4 FALSE Custom`<br \/>\nif [ &#8220;$qpagesize&#8221; == &#8220;Letter&#8221; ]; then<br \/>\npagesize=&#8221;-x 215 -y 280&#8243;<br \/>\nelif [ &#8220;$qpagesize&#8221; == &#8220;Legal&#8221; ]; then<br \/>\npagesize=&#8221;-x 215 -y 355&#8243;<br \/>\nelif [ &#8220;$qpagesize&#8221; == &#8220;A4&#8243; ]; then<br \/>\npagesize=&#8221;-x 210 -y 297&#8243;<br \/>\nelif [ &#8220;$qpagesize&#8221; == &#8220;Custom&#8221; ]; then<br \/>\npagex=`zenity &#8211;entry &#8211;text &#8220;Enter the page width (mm)&#8221; &#8211;title &#8220;Width&#8221;`<br \/>\npagey=`zenity &#8211;entry &#8211;text &#8220;Enter the page height (mm)&#8221; &#8211;title &#8220;Height&#8221;`<br \/>\npagesize=&#8221;-x $pagex -y $pagey&#8221;<br \/>\nfi<\/p>\n<p>#decide grey or colour (gray or color for the Americans!)<br \/>\ncolour=`zenity &#8211;list &#8211;title &#8220;Color or Gray?&#8221; &#8211;radiolist &#8211;column &#8220;-&#8221; &#8211;column &#8220;Scan Mode&#8221; TRUE Gray FALSE Color`<\/p>\n<p>a=0 #page counter<br \/>\ncont=1 #should we continue?<\/p>\n<p>until [ $cont -eq &#8220;0&#8221; ] #keep doing it until cont variable is not a zero.<br \/>\ndo<br \/>\necho -n &#8220;$a &#8221;<br \/>\nlet &#8220;a+=1&#8221;<br \/>\nif zenity &#8211;question &#8211;text &#8220;OK to scan a page, Cancel to finish, Page=$a&#8221; &#8211;title &#8220;Scanning pages&#8221;<br \/>\nthen<br \/>\ncont=1<br \/>\n`scanimage -d $scannerdevice &#8211;format pnm &#8211;resolution $resolution $pagesize &#8211;mode $colour > &#8220;\/tmp\/$a.pnm&#8221;` | zenity &#8211;progress &#8211;auto-close &#8211;title &#8220;Scanning page&#8230;&#8221;<br \/>\nelse<br \/>\ncont=0<br \/>\nfi<\/p>\n<p>done # No surprises, so far.<\/p>\n<p>#convert the raw file to postscript<br \/>\nconvert -density $resolution \/tmp\/*.pnm \/tmp\/out.ps | zenity &#8211;progress &#8211;auto-close &#8211;title &#8220;Converting to Postscript&#8230;&#8221;<\/p>\n<p>#convert the postscript to pdf<br \/>\nps2pdf \/tmp\/out.ps \/tmp\/out.pdf | zenity &#8211;progress &#8211;auto-close &#8211;title &#8220;Converting Postscript to PDF&#8230;&#8221;<\/p>\n<p>#remove raw scan files<br \/>\nrm \/tmp\/*.pnm<\/p>\n<p>#remove old ps files<br \/>\nrm \/tmp\/out.ps<\/p>\n<p>#beep to get attention after processing<br \/>\necho -e &#8220;\\a&#8221;<\/p>\n<p>#add the metadata and file name.<br \/>\n#this meta data can be searched from Beagle in Ubuntu.<\/p>\n<p>#echo &#8220;Please enter a name for the PDF file (** no .pdf on end)&#8221;<br \/>\nnm=`zenity &#8211;entry &#8211;text &#8220;Enter file name, (no .pdf on the end)&#8221; &#8211;title &#8220;File Name?&#8221;`<\/p>\n<p>#echo &#8220;Please enter Metadata for searching&#8221;<br \/>\nmeta=`zenity &#8211;entry &#8211;text &#8220;Meta data for searching&#8221; &#8211;entry-text=$nm &#8211;title &#8220;Meta Data for Searching&#8221;`<\/p>\n<p>echo &#8220;InfoKey: Producer&#8221; > \/tmp\/pdfdata.tmp<br \/>\nif [ &#8220;$producer&#8221; ]; then<br \/>\necho &#8220;InfoValue: $producer&#8221; >> \/tmp\/pdfdata.tmp<br \/>\nelse<br \/>\necho &#8220;InfoValue: $meta&#8221; >> \/tmp\/pdfdata.tmp<br \/>\nfi<br \/>\necho &#8220;InfoKey: Keywords&#8221; >> \/tmp\/pdfdata.tmp<br \/>\necho &#8220;InfoValue: $meta&#8221; >> \/tmp\/pdfdata.tmp<br \/>\necho &#8220;InfoKey: Title&#8221; >> \/tmp\/pdfdata.tmp<br \/>\necho &#8220;InfoValue: $nm&#8221; >> \/tmp\/pdfdata.tmp<\/p>\n<p>#update the metadata<br \/>\npdftk \/tmp\/out.pdf update_info \/tmp\/pdfdata.tmp output &#8220;$outputfolder$nm.pdf&#8221;<\/p>\n<p>#rm metadata file and pdf<br \/>\nrm \/tmp\/pdfdata.tmp<br \/>\nrm \/tmp\/out.pdf<\/p>\n<p>if zenity &#8211;question &#8211;text &#8220;$nm.pdf has been created! Would you like to scan another document?&#8221; &#8211;title &#8220;Thanks!&#8221;; then<br \/>\nrestart=1<br \/>\nelse<br \/>\nrestart=0<br \/>\nfi<\/p>\n<p>done<br \/>\nexit 0\n<\/p><\/blockquote>\n<blockquote><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Mac Jones from New Zealand, created this great bash script that scans pages from your scanner, then turns them into a PDF. Well, I took that script, and improved upon it. Check it out.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=219"}],"version-history":[{"count":0,"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.jasongreb.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}