You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
#!/bin/bash |
|
|
|
function help () { |
|
echo "Usage: $0 <inputfile> [<outputfile>]" |
|
echo "Takes a pdf file, removes any vertical scanner lines, and outputs it as output.pdf if not otherwise specified" |
|
echo " -e remove lines on even pages. First page is page 0 (even)" |
|
echo " -o remove lines on odd pages. First page is page 0 (even)" |
|
echo " -a remove lines on all pages" |
|
echo " -c increase contrast of pdf file" |
|
echo " -h display this output" |
|
exit 1 |
|
} |
|
|
|
while getopts 'eoaclh' opt ; do |
|
case "$opt" in |
|
# v) verbosity=VERBOSE ;; |
|
# q) verbosity=QUIET;; |
|
e) even='true';; |
|
o) odd='true';; |
|
a) even='true'; odd='true';; |
|
c) contrast='true';; |
|
h) help ;; |
|
esac |
|
done |
|
|
|
input_file=${@:$OPTIND:1} |
|
output_file=${@:($OPTIND +1):1} |
|
output_file=${output_file:-'output.pdf'} |
|
|
|
if [ -z "$input_file" ]; then |
|
help |
|
fi |
|
|
|
tmp_dir=$(mktemp -d -t processor-images-XXXXX) |
|
|
|
pdfimages -j "$input_file" "$tmp_dir/page" |
|
|
|
for file in "$tmp_dir"/page-*.jpg |
|
do |
|
filename="${file##*/}" |
|
page_nr="${filename:5:3}" |
|
page_nr=$(echo $page_nr | sed 's/^0*//') # Remove leading zeros |
|
if [ -z "$page_nr" ] |
|
then |
|
page_nr=0 |
|
fi |
|
|
|
echo "Pagenr: $page_nr" |
|
if [ "$contrast" = 'true' ] |
|
then |
|
echo "Increase contrast" |
|
mogrify -level 25% $file |
|
fi |
|
|
|
page_even='true'; [ $((page_nr%2)) -eq 1 ] && page_even='false' |
|
if ( [ "$page_even" = 'true' ] && [ "$even" = 'true' ] ) || ( [ "$page_even" = 'false' ] && [ "$odd" = 'true' ] ) |
|
then |
|
echo Remove line |
|
mogrify -morphology bottomhat "1x100:0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0" -negate $file |
|
fi |
|
done |
|
|
|
convert $tmp_dir/page-*.jpg "$output_file" |
|
rm -rf $tmp_dir |
|
echo "Done! Saved output to $output_file"
|
|
|