How to make screenshot of PDF cover (first page) using command line?

pdf bash convert command-line

Showing list of PDF to downloads could be enhanced with thumbnails of PDF first page, usually cover. This could be used in books catalog, product catalogs etc. Creating thumbnails manually is tedious. This can be automated with pdftoppm command.

To create screenshot of PDF's first page use following command:

pdftoppm -png -f 1 -l 1 test2.pdf > cover.png

The explanation of command options:

  • -png - instructs pdftoppm to create image in PNG format instead of PPM. Can also be used -jpeg for JPG format.
  • -f 1 - First page to print
  • -l 1 - Last page to print

After command options we provide PDF file name. The command outputs directly to stdout. To save file we need to redirect output using > operator.

If you feel that generated image have too large dimensions, use external too to resize. Using options of pdftoppm will not yield good results. 

Example of in-place PDF cover resize:

mogrify -resize 600x600 cover.png

The mogrify command is a part of Imagemagick package and its equivalent of convert command, but does overwrite source file, a.k.a. in-place conversion.