mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
packages/easyscan: complete rewrite
This commit is contained in:
parent
ba1167d989
commit
7f1cece74c
1 changed files with 12 additions and 58 deletions
|
|
@ -1,65 +1,19 @@
|
|||
#
|
||||
# Declare variables
|
||||
#
|
||||
DEVICE="${SANE_DEFAULT_DEVICE:-}"
|
||||
OUTPUT_FILE=
|
||||
# This is here because scanimage's batch mode is broken for my scanner
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-d | --device)
|
||||
# Allows user to override the device used, since scanimage is
|
||||
# slow and the printer might not even change between runs
|
||||
DEVICE="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
OUTPUT_FILE="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Handle defaults
|
||||
#
|
||||
if [ -z "$OUTPUT_FILE" ]; then
|
||||
OUTPUT_FILE=./scan_"$(date)".pdf
|
||||
fi
|
||||
|
||||
if [ -z "$DEVICE" ]; then
|
||||
DEVICE=$(scanimage --formatted-device-list="%d (%v %m)" --list-devices |
|
||||
fzf --header "Pick a device:" |
|
||||
cut -d ' ' -f 1)
|
||||
fi
|
||||
OUTPUT_FILE="${1:-./scan_"$(date)".pdf}"
|
||||
|
||||
tempdir="$(mktemp -d)"
|
||||
|
||||
do_scan() {
|
||||
filename="$tempdir/$(date).pdf"
|
||||
while ! scanimage --format=pdf --device="$DEVICE" --resolution 300 >"$filename"; do
|
||||
:
|
||||
done
|
||||
echo "$filename"
|
||||
}
|
||||
|
||||
do_fix() {
|
||||
read -r filename
|
||||
fixed_name="${filename%.pdf}_fixed.pdf"
|
||||
gs -o "$fixed_name" -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress "$filename"
|
||||
rm "$filename"
|
||||
mv "$fixed_name" "$filename"
|
||||
echo "$filename"
|
||||
}
|
||||
counter=1
|
||||
|
||||
while :; do
|
||||
do_scan | do_fix
|
||||
# If no size is set, the output will be wonky-sized
|
||||
# 210,297 is the size of A4
|
||||
scanimage -x 210 -y 297 --resolution 300 -o "$tempdir/easyscan_$counter.pdf" ||
|
||||
{
|
||||
echo "Failed to scan page..."
|
||||
}
|
||||
|
||||
IFS= read -r -p "Continue scanning ? [Y/n] " cont
|
||||
IFS= read -r -p "Continue scanning? [Y/n] " cont
|
||||
case "$cont" in
|
||||
[nN])
|
||||
echo "Exiting..."
|
||||
|
|
@ -67,12 +21,12 @@ while :; do
|
|||
;;
|
||||
[yY] | *) ;;
|
||||
esac
|
||||
counter=$((counter += 1))
|
||||
done
|
||||
|
||||
# Multiple files are scanned, join them
|
||||
merged_filename="$tempdir/$(date)_final.pdf"
|
||||
merged_filename="$tempdir/easyscan_final.pdf"
|
||||
pdfunite "$tempdir"/*.pdf "$merged_filename"
|
||||
echo "$merged_filename" | do_fix
|
||||
|
||||
# Copy scan to current directory
|
||||
cp "$merged_filename" "$OUTPUT_FILE"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue