# How to add a picture onto an existing pdf file?

I have a scanned pdf file which is an application form, and a picture which is the scanned version of one's signature (for example, this one) and can be in any image format such as eps or png. I would like to put the signature picture on the blank space right to "APPLICANT:" on the second page of the application form. I wonder how to do that in TeX?

I have tried the following non-TeX methods, but none succeeded.

1. The first way is using gimp. I first import the application form into gimp, and then paste the signature picture on the space right to "APPLICANT:" on the second page of the application form.

But the problems are that:

• It seems that I can only import one page of the application form into gimp, not all of the two pages.

• Also when I save the modification, the closest format to pdf I can save to is ps, and the resolution has been downgraded and the storage size of the saved file is 10 times bigger than the original application form and the signature picture.

2. The second way is using Libreoffice Draw. I have installed the libreoffice-pdfimport package. But after I import the application form into Libreoffice Draw,

• all the scanned content is not imported, and

• the layout is different from the layout of the original application form.

So can TeX help? Can it lay the signature picture directly on the application form pdf file,

• without having to convert between formats,
• without having to create much bigger files while keeping the original resolution,
• without having to split and combine pages of a multi-page pdf file,
• without having to rasterize other parts of the pdf file, i.e. without losing the text I later added to the application form pdf file by having to convert the whole pdf into images.

Thanks!

-

## 5 Answers

This can be done with pdflatex easily. You can e.g. use graphicx or pdfpages to import the pdf and a picture-environment to overlay it with some text. Here e.g. an example with eso-pic.

\documentclass{article}
\usepackage{eso-pic}
\usepackage{graphicx}
\AddToShipoutPictureBG*{%
\AtPageLowerLeft{\includegraphics[page=1]{test}}
\AtPageLowerLeft{%
\put(\LenToUnit{8cm},\LenToUnit{10cm}){\Huge\bfseries TEXT}}}%

\begin{document}
\mbox{} % to create a page

\end{document}

-

Like Ulrike Fischer wrote, you could use graphicx or pdfpages for inserting your PDF into the document.

An alternative to eso-pic is the package tikz which you can use to create overlays. For example something along:

\begin{tikzpicture}[overlay]
\node [xshift=150mm,yshift=-80mm]
at (current page.north west) {\includegraphics{signature}} ;
\end{tikzpicture}

-

## Case 1: Overlaying an image on a single-page PDF file

1. User defined data:

\def\BackImage{example-image-a4.pdf}
\def\FrontImage{example-image-a.pdf}

\def\ScaleBack{1}
\def\ScaleFront{0.5}

\def\Columns{10}
\def\Rows{10}

2. Navigation grid:

3. Final result:

4. Minimal Working Example:

Please TeX it with xelatex. Set border to 0 to remove the padding.

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pstricks}
\usepackage{graphicx}

% User defined data:
\def\BackImage{example-image-a4.pdf}
\def\FrontImage{example-image-a.pdf}

\def\ScaleBack{1}
\def\ScaleFront{0.5}

\def\Columns{10}
\def\Rows{10}

% Internal used data:
\newsavebox\IBack
\savebox\IBack{\includegraphics[scale=\ScaleBack]{\BackImage}}

\newsavebox\IFront
\savebox\IFront{\includegraphics[scale=\ScaleFront]{\FrontImage}}

\psset
{
xunit=\dimexpr\wd\IBack/\Columns\relax,
yunit=\dimexpr\ht\IBack/\Rows\relax,
}

\begin{document}

\begin{pspicture}(\Columns,\Rows)
\rput[bl](0,0){\usebox\IBack}
\psgrid
\end{pspicture}

\begin{pspicture}(\Columns,\Rows)
\rput[bl](0,0){\usebox\IBack}
\rput(5,1){\usebox\IFront}
\end{pspicture}

\end{document}


## Case 2: Overlaying an image on each page of a PDF file

% Set border=0 if you have found  the coordinate
% at which you place the front image on the back image.
\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pstricks}
\usepackage{graphicx}

% User defined data:
\def\BackImage{mwe.pdf}
\def\FrontImage{example-image-a.pdf}

\def\ScaleBack{1}
\def\ScaleFront{0.5}

\def\Columns{10}
\def\Rows{10}

% Internal used data:
\newsavebox\IBack
\savebox\IBack{\includegraphics[scale=\ScaleBack,page=2]{\BackImage}}

\newsavebox\IFront
\savebox\IFront{\includegraphics[scale=\ScaleFront]{\FrontImage}}

\psset
{
xunit=\dimexpr\wd\IBack/\Columns\relax,
yunit=\dimexpr\ht\IBack/\Rows\relax,
}

\begin{document}

% Comment out the following code
% to locate the coordinate to overlay the front image on the back image.
%\begin{pspicture}(\Columns,\Rows)
%   \rput[bl](0,0){\usebox\IBack}
%   \psgrid
%\end{pspicture}

\newcount\x
\IfFileExists{\BackImage}{%
\loop
\ifnum\x<\XeTeXpdfpagecount"\BackImage"\relax
\advance\x by 1\relax
\savebox\IBack{\includegraphics[page=\the\x,scale=\ScaleBack]{\BackImage}}%
\begin{pspicture}(\Columns,\Rows)
\rput[bl](0,0){\usebox\IBack}
\rput(0.5\wd\IBack,0.85\ht\IBack){\usebox\IFront}
\end{pspicture}
\repeat
}{%
\noindent\hfill NOTHING! \hfill\null
}%

\end{document}

-
Nice. But in LaTeX we have \newcommand. Please use it instead of \def. –  Martin Schröder Jul 26 '12 at 6:37

As Ulrike already suggested pdfpages is a good option. It offers a picturecommand option which can help you to place something over the included page. Here you have the code I used with your files:

\documentclass[letter]{article}
\usepackage{pdfpages}

\begin{document}
\includepdf[pages={1}]{2012Application}
\newpage
\includepdf[pages={2},%
picturecommand={\setlength\unitlength{1cm}%
\put(6,11){\includegraphics[scale=0.45]{signature}}}]%
{2012Application}
\end{document}


and the result:

-

Notes:

1. Using ImageMagick, convert the signature file from PNG to PDF.
2. Using ImageMagick, convert the application file from PDF to PDF to remove non-standard features. Xe(La)TeX does not like the non-standard features in the original application.
3. For the first TeXing, use the navigation grid to find the location at which you want to put the signature.
4. In the second TeXing, disable the first pspicture (which contains grid) and make sure you change border to 0bp to get a tight output without border.
5. Use XeLaTeX for TeXing.

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pstricks}
\usepackage{graphicx}

% User defined data:
\def\BackImage{Application.pdf}
\def\FrontImage{Signature.pdf}

\def\ScaleBack{1}
\def\ScaleFront{0.4}

\def\Columns{10}
\def\Rows{10}

% Internal used data:
\newsavebox\IBack
\savebox\IBack{\includegraphics[page=2,scale=\ScaleBack]{\BackImage}}

\newsavebox\IFront
\savebox\IFront{\includegraphics[scale=\ScaleFront]{\FrontImage}}

\psset
{
xunit=\dimexpr\wd\IBack/\Columns\relax,
yunit=\dimexpr\ht\IBack/\Rows\relax,
}

\begin{document}

\begin{pspicture}(\Columns,\Rows)
\rput[bl](0,0){\usebox\IBack}
\psgrid
\end{pspicture}

\begin{pspicture}(\Columns,\Rows)
\rput[bl](0,0){\usebox\IBack}
\rput(3.5,4.2){\usebox\IFront}
\end{pspicture}

\end{document}

-