Converting a PDF to PNG

前端 未结 12 1905
一个人的身影
一个人的身影 2020-11-27 09:58

I\'m trying to convert a PDF to a PNG image (at least the cover of one). I\'m successfully extracting the first page of the PDF with pdftk. I\'m using imagemagick to do the

12条回答
  •  旧时难觅i
    2020-11-27 10:20

    Couldn't get the accepted answer to work. Then found out that actually the solution is much simpler anyway as Ghostscript not just natively supports PNG but even multiple different "encodings":

    • png256
    • png16
    • pnggray
    • pngmono
    • ...

    The shell command that works for me is:

    gs -dNOPAUSE -q -sDEVICE=pnggray -r500 -dBATCH -dFirstPage=2 -dLastPage=2 -sOutputFile=test.png test.pdf
    

    It will save page 2 of test.pdf to test.png using the pnggray encoding and 500 DPI.

提交回复
热议问题