mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
packages/easyscan: fix ordering of merged pages
This commit is contained in:
parent
ed71d655d1
commit
86662baa04
1 changed files with 14 additions and 7 deletions
|
|
@ -8,37 +8,44 @@ if [ -e "$OUTPUT_FILE" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tempdir="$(mktemp -d)"
|
tempdir="$(mktemp -d)"
|
||||||
|
filenames=()
|
||||||
counter=1
|
counter=1
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
ok="true"
|
ok="true"
|
||||||
echo "Scanning page $counter"
|
echo "Scanning page $counter"
|
||||||
|
|
||||||
|
CUR_FNAME="$tempdir/easyscan_$counter.pdf"
|
||||||
|
|
||||||
# If no size is set, the output will be wonky-sized
|
# If no size is set, the output will be wonky-sized
|
||||||
# 210,297 is the size of A4
|
# 210,297 is the size of A4
|
||||||
scanimage -x 210 -y 297 --resolution 300 -o "$tempdir/easyscan_$counter.pdf" >/dev/null 2>&1 ||
|
scanimage -x 210 -y 297 --resolution 300 -o "$CUR_FNAME" >/dev/null 2>&1 ||
|
||||||
{
|
{
|
||||||
echo "Failed to scan page..."
|
echo "Failed to scan page..."
|
||||||
ok="false"
|
ok="false"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if $ok; then
|
||||||
|
counter=$((counter += 1))
|
||||||
|
filenames+=("$CUR_FNAME")
|
||||||
|
fi
|
||||||
|
|
||||||
IFS= read -r -p "Continue scanning? [Y/n] " cont
|
IFS= read -r -p "Continue scanning? [Y/n] " cont
|
||||||
case "$cont" in
|
case "$cont" in
|
||||||
[nN])
|
[nN])
|
||||||
echo "Exiting..."
|
echo "Exiting..."
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
[yY] | *)
|
[yY] | *) ;;
|
||||||
if $ok; then
|
|
||||||
counter=$((counter += 1))
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Multiple files are scanned, join them
|
# Multiple files are scanned, join them
|
||||||
|
#
|
||||||
|
# Note: do NOT use the * glob, because bash orders lexicographically and not
|
||||||
|
# numerically, the merged ordering will be wrong.
|
||||||
merged_filename="$tempdir/easyscan_final.pdf"
|
merged_filename="$tempdir/easyscan_final.pdf"
|
||||||
pdfunite "$tempdir"/*.pdf "$merged_filename"
|
pdfunite "${filenames[@]}" "$merged_filename"
|
||||||
|
|
||||||
# Copy scan to current directory
|
# Copy scan to current directory
|
||||||
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue