pdf2jpeg 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # pdf2jpeg
  3. #
  4. # Rasterizes a PDF file, saving as a set of 24 bpp RGB images
  5. #
  6. # input: PDF
  7. # root name of output files
  8. # output: 24 bpp RGB jpeg 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 outjpgroot"
  21. exit -1
  22. fi
  23. inpdffile=$1
  24. outjpgroot=$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. # choose one of the two options below
  36. #--------------------------------------------------------------------#
  37. # output image size depending on resolution #
  38. #--------------------------------------------------------------------#
  39. echo "0 neg 0 neg" translate | gs -sDEVICE=jpeg -sOutputFile=${outjpgroot}%03d.jpg -r300x300 -q - ${tmppdffile}
  40. #echo "0 neg 0 neg" translate | gs -sDEVICE=jpeg -sOutputFile=${outjpgroot}%03d.jpg -r150x150 -q - ${tmppdffile}
  41. #echo "0 neg 0 neg" translate | gs -sDEVICE=jpeg -sOutputFile=${outjpgroot}%03d.jpg -r75x75 -q - ${tmppdffile}
  42. #--------------------------------------------------------------------#
  43. # output fixed image size #
  44. #--------------------------------------------------------------------#
  45. #echo "0 neg 0 neg" translate | gs -sDEVICE=jpeg -sOutputFile=${outjpgroot}%03d.jpg -g2550x3300 -r300x300 -q - ${tmppdffile}