These snippets of code are meant to be run on the command line, especially on a Linux-based machine. They will require extra packages to run.
Using Ghostscrpt
Requires ghostscript package.
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default \
-dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages \
-dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf
Requires poppler-utils.
pdftoppm -png input.pdf outputname
By default images will be at 150dpi resolution but can be altered.