Last active
April 27, 2023 03:57
-
-
Save baojie/5980346 to your computer and use it in GitHub Desktop.
Double-sided scanning in linux and converting to pdf. Dependency: sudo apt-get install xsane imagemagick
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 | |
scanimage --batch --batch-double | |
read -p "Flip papers in the feeder, last page on top. Press [Enter] key to start..." | |
endpage=$(echo "$(ls *.pnm -1 | wc -l) * 2" | bc) | |
scanimage --batch --batch-increment -2 --batch-start $endpage | |
for file in *.pnm; do convert $file $file.jpg; done | |
rm *.pnm | |
convert $(ls *.jpg -1v | paste) -compress jpeg -page A4 output.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome. The only nitpick is that if there are other jpg's in my current folder it will combine all of them into the final pdf. Also, it will
rm
all my preexisting pnm files. I've added a few small thingsLastly, my
convert
does not convert PDF by throwing out the following error:I followed the solution here to comment out
<policy domain="coder" rights="none" pattern="PDF" />
inside/etc/ImageMagick-6/policy.xml
.