# How to set size of pdf page in pixels and put a background image

I need to create certificates in pdf. I have an image, where the text must be put to the appropriate place. I managed to set the correct pdf page size and all margins, except the top:

\documentclass{standalone}
\usepackage[paperwidth=1055px,paperheight=700px]{geometry}
\usepackage{graphicx}
\setlength{\oddsidemargin}{0px}
\begin{document}
\includegraphics{bg.png}
\end{document}


But there is little top margin, that shifts the image out of the page.

How can I set the picture as the background of this page? And remove the margin?

Then I'll use tikz to position the text.

-
Related: Package for certificates –  Werner Apr 11 '13 at 15:58
Wouldn't margin=0pt among the option to geometry help? I would never use px as unit: use bp if you know the precise dimensions of the image in Postscript points (72bp=1in). –  egreg Apr 11 '13 at 21:24
@egreg 1. "Wouldn't margin=0pt among the option to geometry help?" - I tried it, but it didn't work. Produces margins at the bottom & right of the page. I used oddsidemargin & topmargin. Look at my answer below. 2. "I would never use px as unit" - they gave me a picture and told to create a pdf of the same size & use it as a background. That's why I used px. Is bp better in this case as well? –  user4035 Apr 11 '13 at 21:35

pdftex (and most likely also luatex, also I haven't checked) provides a primitive \pdfpxdimen and the unit px. See the pdftex manual, section 7.9. An example from the manual:

\pdfpxdimen=1in % 1 dpi
\divide\pdfpxdimen by 96 % 96 dpi
\hsize=1200px


px should work with the geometry package.

-
Yes, I did it with geometry package. But can't remove the top and left margins. –  user4035 Apr 11 '13 at 15:09
@user4035: It's not nice to remove parts of your question after somebody answered them. Can I at least get an upvote? :-) –  Martin Schröder Apr 11 '13 at 15:10
Sorry, I saw your answer exactly after I saved the edit :). –  user4035 Apr 11 '13 at 15:11

file QXom4.png


QXom4.png: PNG image data, 600 x 399, 8-bit colormap, non-interlaced


Then I created the following file:

\documentclass{article}
\usepackage[margin=0pt,paperheight=399bp,paperwidth=600bp]{geometry}
\usepackage{graphicx}
\parindent=0pt
\pagestyle{empty}
\begin{document}
\includegraphics{QXom4.png}
\end{document}


This produced a PDF file with no margin whatsoever.

However, the simpler

\documentclass{standalone}
\usepackage{graphicx}
\begin{document}
\includegraphics{QXom4.png}
\end{document}


did the same, because standalone automatically clips the PDF to the dimension of its contents.

The default value of 1px is equal to 1bp. Well, 1px is 65782 scaled points, while 1bp is 65781 scaled points (1pt = 65536 scaled points, the difference is negligible). It's not recommended to use it (if you don't set it in your document with \pdfpxdimen), because it can be changed at format creation.

-
I improved my answer, using your suggestions. With standalone the code is much better. –  user4035 Apr 11 '13 at 21:55

I did it:

\documentclass{standalone}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{color}
\usepackage{tikz}
\definecolor{green}{RGB}{0,101,0}
\color{green}
\begin{document}
\fontsize{12mm}{11mm}\selectfont
\begin{tikzpicture}
\draw node[inner sep=0] {\includegraphics{bg.png}};
\draw (1, 1) node[align=center] {mr. Dummy\\
Group Name};
\node at (7.4cm, -3.09cm) {10.01.2013};
\end{tikzpicture}
\end{document}


Gives this:

-