# How to make each PDF page of a beamer output have an opaque background when it is converted to a PNG image?

I want to get an opaque background for each PDF page of beamer output that is converted to a PNG image. I attempted to change \setbeamercovered{transparent=50} but it made the whole PDF pages have the same content as the last page does.

Is there such an option in beamer to make an opaque background?

\documentclass{beamer}
%\setbeamercovered{transparent=50}
\usepackage{tikz}

\usepackage[active,tightpage]{preview}
\PreviewBorder=12pt
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{scope}
\fill[orange] (-1.4,-2) rectangle (-0.8,2);\pause
\fill[blue] (-1.4,1.5) -- (0.2,1.5) -- (1.2,0.8) -- (1.2,2) --(-1.2,2) -- cycle;\pause
\fill[yellow] (-0.75,1.5) -- (0.2,1.5) -- (0.8,1) -- (0.6,0.2) --(0.2,0) -- (-0.75,0) -- cycle;\pause
\fill[magenta] (0.8,1) -- (0.6,0.2) --(0.2,0) -- (0.8,-0.8) -- (0.8,-1.4) -- (1.4,-1.4) -- (1.4,1) --cycle;\pause
\node[scale=12,inner sep=0pt] {R};
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}


How to make each PDF page of a beamer output have an opaque background when it is converted to a PNG image?

-
Thank you for editing. I forgot the rule subject1 + make(s) + object1 + verb (always in plural context) + object2. – kiss my armpit Jul 27 '12 at 17:40

Beamer frames with default theme have always a white background.

Your MWE is not a beamer document. It is some tikzpictures extracted by preview.

You can add a white background to each tikzpicture by filling bounding box using special node current bounding box and pgfonlayer environment (provided by backgrounds TikZ library):

\documentclass{beamer}
%\setbeamercovered{transparent=50}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage[active,tightpage]{preview}
\PreviewBorder=12pt
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{scope}
\fill[orange] (-1.4,-2) rectangle (-0.8,2);\pause
\fill[blue] (-1.4,1.5) -- (0.2,1.5) -- (1.2,0.8) -- (1.2,2) --(-1.2,2) -- cycle;\pause
\fill[yellow] (-0.75,1.5) -- (0.2,1.5) -- (0.8,1) -- (0.6,0.2) --(0.2,0) -- (-0.75,0) -- cycle;\pause
\fill[magenta] (0.8,1) -- (0.6,0.2) --(0.2,0) -- (0.8,-0.8) -- (0.8,-1.4) -- (1.4,-1.4) -- (1.4,1) --cycle;\pause
\node[scale=12,inner sep=0pt] {R};
\end{scope}
\begin{pgfonlayer}{background}
\fill[white]
(current bounding box.south east)
rectangle
(current bounding box.north west);
\end{pgfonlayer}
\end{tikzpicture}
\end{frame}
\end{document}

-
Rather than modifying the TikZ or PSTricks code by filling the transparent regions, I prefer leave them as is but convert the PDF output to PNG using -alpha off option provided by ImageMagick command convert. The switch also works for making GiF animation. – kiss my armpit Jul 27 '12 at 19:23
you really would not want to use the -alpha off option from convert as will removes entirely the anti-aliasing during the conversion, rendering the image rather badly, especially when text is involved. The alternative to the -alpha off option is what I explain in my answer. – ArTourter Jul 27 '12 at 22:09
@ArTourter: I have tried your answer but it works only for a single-page PDF and produces a single PNG image. For a multi-page PDF, your method always produces a single PNG. The total number of PNG images should be the same as that of PDF pages in the converted PDF file. Do you have idea to solve it? – kiss my armpit Jul 28 '12 at 5:20
@HiggsBoson You can use pdftoppm. For example, pdftoppm -r 100 file.pdf file-root gives a PPM file (file-root-1.ppm, file-root-2.ppm...) for each page. – Paul Gaborit Jul 28 '12 at 8:30

Although not strictly a TeX issue, you can use options to the convert tool from imagemagick to do this. The two options to use are the -background and the -flatten. The first one sets the background color, but the second is needed as by default the output would be layered which doesn't quite work in png.

My usual command for output png from pdf, which I use to post screenshots here looks like:

convert -density 600 -background white -flatten -resize 600 file.pdf file.png


The order is fairly important as it influence the quality of the output.

The density and resize options also helps with the quality of the output but are not really related although they actually help with with dealing with the -flatten option somehow. (in terms or units, density is in DPI, resize is in pixels, and when only one number is given correspond to the width of the output file, the height being scaled appropriately while keeping the source aspect ratio)

The point of the density/resize part is to choose a density which, without resizing, would be at least twice as large as the dimension of the image you actually want to get.

-
how about -alpha remove? – kiss my armpit Jul 28 '12 at 8:48