Convert PDFs to png with Ubuntu

Here is a small snippet for converting PDF files to PNG using the package imagemagick in Ubuntu. Depending on the desired quality of the images, you can set the dpi with the density parameter. Flattening of all layers is enabled and a white background is added. Omit the latter for transparent background if the PDF has transparency enabled.

convert -background white -density 180 -flatten image.pdf image.png

If the resulting image has distorted colors or contrast, try a different colospace.

convert -background white -density 180 -colospace sRGB -flatten image.pdf image.png