I am converting a PDF (which I made with R) to a PNG with a command like this:

convert -density 200 foo.pdf bar.png

This generates a PNG allright, but the white background is transparent in the resulting PNG. This is not what I want, I want the background to be white in the PNG as well. How can I achieve this?


  • I am using Xubuntu.
  • What is weird, I did the same sequence on a different linux and computer: first generate picture with R in PDF format, then convert from PDF to PNG, and on that installation it does not convert the white background into transparency, just as I want it. But, I do not know where the difference is caused (R, convert or what).

3 Answers 3


Try to add this setting:



  • Note that if the original PDF has multiple pages, this will result in the content of different pages superimposed on each other.
    – gerrit
    Jul 13, 2018 at 15:07

Best way is to add -alpha remove -alpha off because -flatten merges all pages if any and would be depreciated ( -layers flatten is recommended )


This is an R solution, but you can also take care of this by generating the graphics in R. For example, the pdf() function has an argument bg that allows you to change the background color of your graphics. You can also generate png files directly using the png function.

R documentation links:

You must log in to answer this question.