12

How do I create a pdf file with a transparent background?

\documentclass{article}
\usepackage{xcolor}

\begin{document}
    \nopagecolor 
    hi
\end{document}

This doesn't work since \nopagecolor resets the page color to the default background, but how do I make it transparent, as one can with e.g. a png image?

  • I was under the impression that a pdf would default to transperant. You don't need any special code for it. Open the pdf in an image-editor, and you will see that it is transperant. – Runar Aug 7 '16 at 20:17
  • Hmm. In gimp it opens with a white background. – JPi Aug 7 '16 at 20:20
  • I tried opening a transperant pdf with gimp and you are right, it turns into a white background. Might be a bug in Gimp. – Runar Aug 7 '16 at 20:36
  • 1
    You can use Image Magic, it will display a transparent background with \nopagecolor or if background is not explicitly set (which is transparent by default). – alwaysask Aug 7 '16 at 20:58
10

\nopagecolor of pdftex.def (and LuaTeX) disables the page color, it does not use any other color like white. Compare and look closely at the cropped images:

\documentclass{article}
\usepackage{xcolor}

\begin{document}
  % Page 1
  \nopagecolor
  \verb|\nopagecolor|
  \newpage

  % Page 2
  \pagecolor{white}
  \verb|\pagecolor{white}|
\end{document}

Page 1 with \nopagecolor

Page 2 with \pagecolor{white}

The second page has a white background.

The first page does not have a background, which can also be verified by the page stream operators for the first page with some added comments:

stream
0 g 0 G  % set black as fill and stroke color
0 g 0 G  % set black as fill and stroke color
0 g 0 G  % set black as fill and stroke color
BT  % begin text
/F15 9.9626 Tf 148.712 657.235 Td [(\134nopagecolor)]TJ  % Write "\nopagecolor"
0 g 0 G  % set black as fill and stroke color
0 g 0 G  % set black as fill and stroke color
ET  % end text
endstream

The white background of GIMP adds the white background. I have not seen an option to disable it (version 2.8). If the white color is only used for the background, then option "Colors → Color to Alpha" can convert white back to the alpha transparency channel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.