pdf2png-binary 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # pdf2png-binary
  3. #
  4. # Rasterizes a PDF file, saving as a set of binary png images
  5. #
  6. # input: PDF
  7. # root name of output files
  8. # output: 1 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. # need mysterious "primer"
  26. # choose one of the two options below
  27. # output image size depending on resolution
  28. echo "0 neg 0 neg" translate | gs -sDEVICE=pngmono -sOutputFile=${outpngroot}%03d.png -r300x300 -q - ${inpdffile}
  29. # output fixed image size
  30. #echo "0 neg 0 neg" translate | gs -sDEVICE=pngmono -sOutputFile=${outpngroot}%03d.png -g2550x3300 -r300x300 -q - ${inpdffile}