December 19, 2020
So, you have a couple of PDF files which you want to convert to images, and all your GUI tools available or known to you failed you; what to do?
Install Ghostscript, make sure its binaries are in your
$PATHto not lose sanity typing out the commands.
Run the following command:
gs -sDEVICE=tiff24nc -sCompression=lzw -r300x300 -dNOPAUSE -sOutputFile="path/to/output/filename%04d.tif" inputfile.pdf
It will take
inputfile.pdf and convert all its pages to LZW-compressed TIFF files with square 300dpi resolution into
%04d token will be replaced with the page number.
After that one can convert the resulting TIFF file to any other image format using myriad of image viewers/editors, including Paint.
gs is the name of the main Ghostscript executable, in the specific package I downloaded from GS website the binary have been named
Courtesy of Drake Dwornik
Now let’s provide some context.
I had a couple of PDF files and I had to make a thumbnails for them, to include here on the website. But, I am one of those obscure personas who didn’t pay for Adobe software and don’t have it installed on the workstation at the same time.
I don’t have Adobe Acrobat Pro, which would be a no-brainer to use in my case. Usually I am using the excellent XnView MP software for image viewing and manipulation, but it told me that I have to install Ghostscript to enable support for PDF files. Which I did.
It did not help — XnView MP still continued to show me the message box that it requires installed Ghostscript to support PDF files.
I decided that it’d be too much of a hassle to dig into this problem and it would be simpler just to use the Ghostscript directly. The reason XnView MP (and a lot of other software out there) requires GS to support PDFs is that GS is basically a de facto PDF renderer for open source and freeware. It’s, to put it simply, a godsend.
And short googling confirmed my thoughts: just the second link I’ve clicked led me to the article which described exactly that: using Ghostscript directly to convert PDF to pictures. TIFFs were enough for me as I have everything I need to convert any image format to any other image format. I would even use the TIFFs directly, would they be supported in Chrome (hint: no, they are not, even RGB ones, at least not while being LZW-compressed).