pdf2png-gray 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # pdf2png-gray
  3. #
  4. # Rasterizes a PDF file, saving a set of 8 bpp grayscale png images
  5. #
  6. # input: PDF
  7. # root name of output files
  8. # output: 8 bpp png files for each page
  9. #
  10. # Note 1: Requires ghostscript
  11. #
  12. # Note 2: A modern alternative to ghostcript is to use poplar:
  13. # If the pdf is composed of images that were orthographically generated:
  14. # pdftoppm -png <pdf-file> <pdf-root> [output in png]
  15. # If the pdf is composed of images that were scanned:
  16. # pdftoppm -jpeg <pdf-file> <pdf-root> [output in jpeg]
  17. scriptname=${0##*/}
  18. if test $# != 2
  19. then
  20. echo "usage: " $scriptname " inpdffile outpngroot"
  21. exit -1
  22. fi
  23. inpdffile=$1
  24. outpngroot=$2
  25. # strip off directory and suffix parts of $1 to use in other names
  26. basename=${1##*/}
  27. baseroot=${basename%.*}
  28. # make names for temporary files
  29. tmppdffile=${baseroot}.$$_.pdf
  30. tmppdfroot=${tmppdffile%.*}
  31. # have the temporary files deleted on exit, interrupt, etc:
  32. trap "/bin/rm -f ${tmppdfroot}*" EXIT SIGHUP SIGINT SIGTERM
  33. cp $inpdffile $tmppdffile
  34. # need mysterious "primer"
  35. #echo "0 neg 0 neg" translate | gs -sDEVICE=pnggray -sOutputFile=${outpngroot}%03d.png -r300x300 -q - ${tmppdffile}
  36. echo "0 neg 0 neg" translate | gs -sDEVICE=pnggray -sOutputFile=${outpngroot}%03d.png -g2550x3300 -r300x300 -q - ${tmppdffile}