Firstly,
Define the bounding box of your first PDF page:
gs \ -q \ -dBATCH \ -dNOPAUSE \ -sDEVICE=bbox \ -dLastPage=1 \ stackoverflowQuestion.pdf \ 2>&1 \ | grep %%BoundingBox
The resulting result will be:
%%BoundingBox: 119 531 464 814
It means:
- the lower left corner of the bounding box is at the coordinate
(119,531) - the upper right corner of the bounding box is at the coordinate
(464,814)
Values ββare at PostScript points (where 72 pt == 1 inch ). A bounding box is a rectangle that includes these PDF graphics that leave ink or toner marks on the page.
Then
create your PNG.
Coming out of the bounding box, it seems to you that it has a width of 345 pt ( = 464 - 119 ) and 283 pt high ( = 814 - 531 ). This results in a page size of -g345x283 (specified in pixels, since Ghostscript uses 72 dpi by default to display the image (unless otherwise specified), and for this 72 px == 1 inch .
Or better, we keep the security zone 1 pt from the bounding box, so we make the image a little bigger than the minimum minimum, and we get this image dimension: -g347x285 .
You also need to cut 119 pt from the left edge (118 pt for βsecurityβ) and 531 pt from the bottom edge (530 for security).
Therefore, the command will be:
gs \ -o out.png \ -sDEVICE=pngalpha \ -g347x285 \ -dLastPage=1 \ -c "<</Install {-118 -530 translate}>> setpagedevice" \ -f stackoverflowQuestion.pdf
Here is the PNG result:

For better PNG quality, increase the resolution from the standard 72 dpi to 720 dpi and use the following command:
gs \ -o out720dpi.png \ -sDEVICE=pngalpha \ -r720 \ -g3470x2850 \ -dLastPage=1 \ -c "<</Install {-118 -530 translate}>> setpagedevice" \ -f stackoverflowQuestion.pdf
Update:
On Windows in the CMD window, the names of the console applications for Ghostscript are: gswin32c.exe and / or gswin64c.exe (instead of gs ). In addition, you will need to use ^ as a line continuation character (instead of \ ).