Created
January 4, 2013 15:11
-
-
Save orymate/4453291 to your computer and use it in GitHub Desktop.
Get scanned images as a single PDF file from web user interface of Canon iR2870.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get scanned images as a single PDF file from Canon iR2870 user mailboxes. | |
# Original author: ŐRY Máté <orymate at iit.bme.hu> | |
# Public domain. Originally published at https://gist.github.com/orymate | |
# Requirements: imagemagick, pdftk, jbgtopbm <http://www.cl.cam.ac.uk/~mgk25/jbigkit/> | |
#set -x | |
SERVER='10.0.0.xxx' | |
if [ $# -lt 2 -o $# -gt 4 ] | |
then | |
echo Usage: $0 MAILBOX DOCUMENT [OUTPUT.pdf] [even] | |
fi | |
cookies=$(mktemp) | |
MAILBOX=$1 | |
DOCUMENT=$(tr -dc 0-9 <<<"$2") | |
OUTPUT=${3:-OUTPUT.pdf} | |
EVEN=${4:-no} | |
# get sessid | |
wget --keep-session-cookies --save-cookies $cookies "http://$SERVER/" -O/dev/null | |
## list mailboxes | |
#d=$(date +%s) | |
#wget --keep-session-cookies --load-cookies $cookies "http://$SERVER/bpbl.cgi?BoxKind=UserBox&Dummy=$d" -O- #-O/dev/null | |
#read | |
# log in! | |
d=$(date +%s) | |
wget --load-cookies $cookies "http://$SERVER/blogin.cgi?BOX_No=$MAILBOX&Cookie=&Dummy=$d" -O/dev/null | |
## get mailbox | |
#d=$(date +%s) | |
#wget --load-cookies $cookies "http://$SERVER/bdocs.cgi?BOX_No=$MAILBOX&DocStart=1&DIDS=&Dummy=$d" -O- | |
#read | |
#d=$(date +%s) | |
#I=1 | |
#URI="http://$SERVER/image.jbg?B=$MAILBOX&D=$DOCUMENT&P=$I&M=M&RX=600&RY=600&Dummy=$d" | |
#URI="http://$SERVER/image.jbg?B=$MAILBOX&D=$DOCUMENT&P=$I&M=MX&RX=600&RY=600&Dummy=$d" | |
#wget --load-cookies $cookies --save-headers $URI -O- | |
#read | |
t=$(mktemp -d) | |
I=1 | |
while true | |
do | |
d=$(date +%s) | |
URI="http://$SERVER/image.jbg?B=$MAILBOX&D=$DOCUMENT&P=$I&M=MV&RX=600&RY=600&Dummy=$d" | |
wget --load-cookies $cookies $URI -O$t/page_$(printf "%04d" $I).jbg | |
if grep -qs "Document does not exist." $t/page_$(printf "%04d" $I).jbg | |
then | |
#echo $t | |
rm $t/page_$(printf "%04d" $I).jbg | |
pdftk $t/*.pdf output "$OUTPUT" && rm -r $t | |
echo $[$I-1] pages written to | |
echo "$OUTPUT" | |
rm $cookies | |
exit 0 | |
fi | |
jbgtopbm $t/page_$(printf "%04d" $I).jbg > $t/page_$(printf "%04d" $I).pbm | |
convert -density 150 -resize 25% -rotate 270 $t/page_$(printf "%04d" $I).{pbm,pdf} | |
rm $t/page_$(printf "%04d" $I).{pbm,jbg} | |
let I++ | |
if [ $EVEN = even ] | |
then | |
let I++ | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment