User Tools

Site Tools


software:unpaper_test

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
software:unpaper_test [2009/08/22 06:45]
admin
software:unpaper_test [2015/04/22 21:51] (current)
admin [findblack]
Line 34: Line 34:
  str1="0.$nmb"  str1="0.$nmb"
  
- unpaper -b $str1 $donot -t pbm /tmp/$ptmpf-1.pgm /tmp/$ptmpf.pbm+ unpaper -b $str1 $donot -t pbm $ptmpf-1.pgm $ptmpf.pbm
  
  # convert inputfile option annotation outputfile  # convert inputfile option annotation outputfile
- convert /tmp/$ptmpf.pbm -gravity NorthWest -annotate 0 "unpaper -$str1 $donot" /tmp/$ptmpf_ca.pbm + convert $ptmpf.pbm -gravity center -background lightblue -font Open-Sans -pointsize 60 caption:"$str1 \n $donot" -composite $ptmpf_ca.pbm 
- convert -monochrome -density 300 -units PixelsPerInch /tmp/$ptmpf_ca.pbm ps:- | ps2pdf13 -sPAPERSIZE=a4 - "/tmp/$ptmpf-$nmb.pdf" + convert -monochrome -density 300 -units PixelsPerInch /$ptmpf_ca.pbm ps:- | ps2pdf13 -sPAPERSIZE=a4 - "$ptmpf-$nmb.pdf" 
- rm /tmp/$ptmpf.pbm /tmp/$ptmpf_ca.pbm + rm $ptmpf.pbm $ptmpf_ca.pbm 
- pdflst="$pdflst /tmp/$ptmpf-$nmb.pdf"+ pdflst="$pdflst $ptmpf-$nmb.pdf"
  nmb=$(($nmb+1))  nmb=$(($nmb+1))
 done done
Line 175: Line 175:
  exit 1  exit 1
  else  else
- # convert first page to a pgm file with filename /tmp/$ptmpf-*.pgm + # convert first page to a pgm file with filename $ptmpf-*.pgm 
- pdftoppm -gray -r 300 "$arg1" /tmp/$ptmpf+ pdftoppm -gray -r 300 "$arg1" $ptmpf
  
  # Check for document resize neccessity. Iterating through all pages, makes sure, all pages get uniform resizing later.  # Check for document resize neccessity. Iterating through all pages, makes sure, all pages get uniform resizing later.
Line 183: Line 183:
  # Iterate through files. We need to sort files in a numerical order because pdftoppm generates files without a leading zero.   # Iterate through files. We need to sort files in a numerical order because pdftoppm generates files without a leading zero. 
  # However before the numbers, a '-' delimiter character had been added by pdftoppm. Now cut the part before that.  # However before the numbers, a '-' delimiter character had been added by pdftoppm. Now cut the part before that.
- for filenum in $(ls /tmp/$ptmpf-*.pgm | cut -d'-' -f2 | sort -n); do + for filenum in $(ls $ptmpf-*.pgm | cut -d'-' -f2 | sort -n); do 
- dimension="$(identify -format "%[fx:w]x%[fx:h]" /tmp/$ptmpf'-'$filenum)"+ dimension="$(identify -format "%[fx:w]x%[fx:h]" $ptmpf'-'$filenum)"
  #  width: "${dimension%%x*}" -> From the end removes the longest part of dimension that matches x* and returns the rest.  #  width: "${dimension%%x*}" -> From the end removes the longest part of dimension that matches x* and returns the rest.
  #  height: "${dimension##*x}" -> From the beginning removes the longest part of dimension that matches *x and returns the rest.  #  height: "${dimension##*x}" -> From the beginning removes the longest part of dimension that matches *x and returns the rest.
Line 215: Line 215:
  echo Some images exceed the maximum size. Now scaling to "$scale"%.  echo Some images exceed the maximum size. Now scaling to "$scale"%.
  # iterate through all files and resize all with the same percentage, use 8 bits per pixel  # iterate through all files and resize all with the same percentage, use 8 bits per pixel
- for filenum in $(ls /tmp/$ptmpf-*.pgm | cut -d'-' -f2 | sort -n); do + for filenum in $(ls $ptmpf-*.pgm | cut -d'-' -f2 | sort -n); do 
- mogrify -depth 8 -resize "$scale"% "/tmp/$ptmpf-$filenum" + mogrify -depth 8 -resize "$scale"% "$ptmpf-$filenum" 
- echo resizing file: "/tmp/$ptmpf-$filenum"+ echo resizing file: "$ptmpf-$filenum"
  done  done
  fi  fi
  # apply unpaper onto each page  # apply unpaper onto each page
- for filenum in $(ls /tmp/$ptmpf-*.pgm | cut -d'-' -f2 | sort -n); do+ for filenum in $(ls $ptmpf-*.pgm | cut -d'-' -f2 | sort -n); do
  # Parameter expansion: ${param%word} From the end remov? Mis je nog iets?es the smallest part of param that matches word and returns the rest. (p.72)  # Parameter expansion: ${param%word} From the end remov? Mis je nog iets?es the smallest part of param that matches word and returns the rest. (p.72)
- unpaper -b $b_threshold $filter $donot -t pbm "/tmp/$ptmpf-$filenum" "/tmp/$ptmpf-"${filenum%.pgm}.pbm + unpaper -b $b_threshold $filter $donot -t pbm "$ptmpf-$filenum" "$ptmpf-"${filenum%.pgm}.pbm 
- rm "/tmp/$ptmpf-$filenum"+ rm "$ptmpf-$filenum"
  done  done
  
  # center pbm page on an a4 canvas, convert to pdf  # center pbm page on an a4 canvas, convert to pdf
  pdflst=""  pdflst=""
- for filenum in $(ls /tmp/$ptmpf-*.pbm | cut -d'-' -f2 | sort -n); do + for filenum in $(ls $ptmpf-*.pbm | cut -d'-' -f2 | sort -n); do 
- convert -size $pdim xc:white miff:- | composite -density $pres -units PixelsPerInch -compose atop -gravity Center "/tmp/$ptmpf-$filenum" - miff:- | convert -monochrome -density 300 -units PixelsPerInch - ps:- | ps2pdf13 -sPAPERSIZE=a4 - "/tmp/$ptmpf-"${filenum%.pbm}.pdf + convert -size $pdim xc:white miff:- | composite -density $pres -units PixelsPerInch -compose atop -gravity Center "$ptmpf-$filenum" - miff:- | convert -monochrome -density 300 -units PixelsPerInch - ps:- | ps2pdf13 -sPAPERSIZE=a4 - "$ptmpf-"${filenum%.pbm}.pdf 
- rm "/tmp/$ptmpf-$filenum" + rm "$ptmpf-$filenum" 
- pdflst="$pdflst /tmp/$ptmpf-"${filenum%.pbm}.pdf+ pdflst="$pdflst $ptmpf-"${filenum%.pbm}.pdf
  done  done
  
Line 340: Line 340:
  fi  fi
  # convert first page to a pgm file with filename tmpfile_PID-1.pgm  # convert first page to a pgm file with filename tmpfile_PID-1.pgm
- pdftoppm -gray -r 300 -f $defpage -l $defpage "$arg1" /tmp/$ptmpf+ pdftoppm -gray -r 300 -f $defpage -l $defpage "$arg1" $ptmpf
  # check for succesful conversion to .pgm  # check for succesful conversion to .pgm
- if [ ! -f "/tmp/$ptmpf-$trail$defpage.pgm" ]; then+ if [ ! -f "$ptmpf-$trail$defpage.pgm" ]; then
  echo "$_fbcvrt"  echo "$_fbcvrt"
- rm "/tmp/$ptmpf-$trail$defpage.pgm"+ rm "$ptmpf-$trail$defpage.pgm"
  exit 1  exit 1
  else  else
Line 360: Line 360:
    
  # process unpaper  # process unpaper
- unpaper -b $str1 $donot -t pbm /tmp/$ptmpf-$trail$defpage.pgm /tmp/$ptmpf.pbm+ unpaper -b $str1 $donot -t pbm $ptmpf-$trail$defpage.pgm $ptmpf.pbm
    
  # Create white A4 size canvas -> center pbm file into canvas -> convert pbm to ps -> convert ps to pdf  # Create white A4 size canvas -> center pbm file into canvas -> convert pbm to ps -> convert ps to pdf
Line 367: Line 367:
  # Sending result to next command with pipe: |  # Sending result to next command with pipe: |
  # Using this 'technique' we don't need to create temporary files.  # Using this 'technique' we don't need to create temporary files.
- convert -size $pdim xc:white miff:- | composite -density $pres -units PixelsPerInch -compose atop -gravity Center /tmp/$ptmpf.pbm - miff:- | convert - $pstr "$ptxt $str1" - | convert -monochrome -density 300 -units PixelsPerInch - ps:- | ps2pdf13 -sPAPERSIZE=a4 - "/tmp/$ptmpf-$nmb.pdf"+ convert -size $pdim xc:white miff:- | composite -density $pres -units PixelsPerInch -compose atop -gravity Center $ptmpf.pbm - miff:- | convert - $pstr "$ptxt $str1" - | convert -monochrome -density 300 -units PixelsPerInch - ps:- | ps2pdf13 -sPAPERSIZE=a4 - "$ptmpf-$nmb.pdf"
    
- pdflst="$pdflst /tmp/$ptmpf-$nmb.pdf"+ pdflst="$pdflst $ptmpf-$nmb.pdf"
  nmb=$(($nmb+$s))  nmb=$(($nmb+$s))
- rm /tmp/$ptmpf.pbm+ rm $ptmpf.pbm
  done  done
- rm /tmp/$ptmpf-$trail$defpage.pgm+ rm $ptmpf-$trail$defpage.pgm
  # Merge all pdf files in $pdflst into one single file with filename $2  # Merge all pdf files in $pdflst into one single file with filename $2
  gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$2 $pdflst  gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$2 $pdflst
software/unpaper_test.txt · Last modified: 2015/04/22 21:51 by admin