# How can I superimpose LaTeX / TeX output over a PDF file?

I have a form as a PDF file. I would like to use LaTeX/TeX to overlay my text over the form, and send the output to either a print or another PDF file.

Is this possible? How would I go about it?

-

A very simple but powerful way is to use the overpic package together with the LaTeX picture environment. It has a grid to position your text, you can work in absolute units or as a percentage of the figure dimensions, etc.

\usepackage[abs]{overpic}
\usepackage{pict2e}


Then you can use it anywhere

\begin{overpic}[scale=1.0,unit=1mm,grid]{Figure file}
:
:
\end{overpic}

-

One idea is to include pdf page using pdfpages (see pdfpages at CTAN), and then put a tikzpicture on top. Tikzpicture can be absolutely positioned with remember picture, overlay option. The question is similar to Can I add tikzpictures to pages included with pdfpages.

A MWE would look like this:

\documentclass[12pt]{article}

\usepackage{pdfpages}
\usepackage{tikz}
\begin{document}
\includepdf[pagecommand={\begin{tikzpicture}[remember picture, overlay]\node at (current page.center) {overlayed text};\end{tikzpicture}}]{filename}
\end{document}

-
 +1 I've just used exactly this method to fill in a form and it works quite nicely. – Andrew Stacey Apr 8 '11 at 18:52

You can use TikZ to place the form as image at the center of an otherwise empty page and then draw on it. This is similar to the suggested pdfpages solution but avoid passing around the tikzpictures, which isn't really necessary.

See also Drawing on an image with TikZ and Is there the easiest way to toggle (show/hide) navigational grids in TikZ? for related code.

You could even add real PDF form fields to it. See Creating fillable PDFs for how it can be done.

\documentclass[letterpaper]{article}% ensure identical page size

\usepackage{tikz}

\pagestyle{empty}
\begin{document}
% Page 1
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.center) {\includegraphics[page=1]{form}};
\begin{scope}[shift={(current page.south west)},every node/.style={anchor=base west}]
% Grid to help find the positions (remove in final version)
\draw [help lines] (0,0) grid (current page.north east);
\draw [help lines,thick] (0,0) grid [step=5cm] (current page.north east);
%
\node at (2cm,9.75cm) {John Doe};
\node at (13cm,9.75cm) {\today};
\end{scope}
\end{tikzpicture}
\clearpage
% Page 2
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.center) {\includegraphics[page=2]{form}};
\begin{scope}[shift={(current page.south west)},every node/.style={anchor=base west}]
% Grid to help find the positions (remove in final version)
\draw [help lines] (0,0) grid (current page.north east);
\draw [help lines,thick] (0,0) grid [step=5cm] (current page.north east);
%
%\node at (2.5cm,10.75cm) {John Doe};
\end{scope}
\end{tikzpicture}
\clearpage
\end{document}


This example used the IEEE copyright form. Just download it and rename it to form.pdf. The second page actually does not include any fillable form fields, but I found it important to show how to handle multiple pages.

-

This answer by Michael Underwood to question PDF letterhead as document background provides a solution using the wallpaper package.

-

The eso-pic package provides a means for adding content to the background or foreground of a page at shipout - the package is an extension of the everyshi package. Therefore, you could typeset your overlay text in the foreground and source PDF pages (via the pdfpages package) using

\AddToShipoutPictureFG*{%
}
\includepdf[pages=X]{<source pdf>}%


where X refers to the specific page in <source pdf> you want to overlay with <your overlay text>. This addition of overlay text has to be done on a per-page basis (hence the starred * version of \AddToShipoutPictureFG). eso-pic provides a means for adding a grid in order to fine-tune the placement of content, as well as some "helper macros" the are predefined in terms of the layout position:

• \AtPageUpperLeft{...} - paper-related positions
• \AtPageLowerLeft{...}
• \AtPageCenter{...}
• \AtTextUpperLeft{...} - text block-related positions
• \AtTextLowerLeft{...}
• \AtTextCenter{...}
• \AtStockUpperLeft{...} - stock-related positions (if using the memoir document class)
• \AtStockLowerLeft{...}
• \AtStockCenter{...}

These placment macros could be nested inside \AddToShipoutPictureFG* for relative positioning.

-
 I got pdfpages to render a whole 210 page pdf from the outset which seems most practical than to put page=1 page=2 etc etc but how would you begin writing on the next page would it just be a case of\newpage and you will be on the next page beginning a new shipoutforground text box... im just a little sketpical about this method thats all and feel that at the 75th page when i go onto a new page everything will mess up and ill be back to the drawing board. So im actually using overpic on each page atm , takes about 5 minutes to enter the page numbers for 140 page document but by default the floa – john Sep 5 '11 at 22:29

I've just used LaTeX to fill in a form that was sent to me as a PDF. The form was not a proper PDF form, just an ordinary PDF with spaces where I should write/type. Previously, I've either used xournal or used the method outlined by ipvalic above. I prefer the control of LaTeX but find it a little tedious with positioning. However, I recently was told about WhizzyTeX and advi (via How can I execute a macro for every node in TikZ?) and thought that it might make it easier to do this. Which it does!

Here's my document:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{wallpaper}
\usepackage{ifpdf}
\thispagestyle{empty}
\pagestyle{empty}

\ifpdf
\def\bgext{pdf}
\else
\def\bgext{ps}
\fi

\makeatletter
\tikzset{
anchor=south west,
#1,
},
x/.initial=0,
y/.initial=0,
\tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode.north east)
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode.south west)
}
}
\makeatother

}

\begin{document}
\CenterWallPaper{1}{FormToFill.\bgext}%
\begin{tikzpicture}[x=1em,y=1em,overlay]
\end{tikzpicture}
\end{document}


It's mostly taken from How can I execute a macro for every node in TikZ?.

When used with WhizzyTeX mode in Emacs and the advi previewer then it is possible to drag the nodes around on the page and so position them exactly where wanted. Thus control over the text via TeX and control over the positioning via drag-and-drop. Perfect.

The main wrinkle with this method is that the previewer is a DVI previewer, not PDF. So to display the PDF background we have to have a version available that the previewer will display. Experiments show that PS is fine. When compiling with pdflatex then it complains a lot about non-DVI specials, so we turn off the special repositioning stuff if compiled with pdflatex. The idea is that we use advi to get the positioning right but then use pdflatex to produce the final version.

I'm not claiming to have figured out all the best ways to do this - it's only the first time I've used it and it took a little tweaking to get it a working system, but next time it'll be much, much easier (if anyone has any suggestions for improvements, please let me know).

And, yes, that is my middle name.

-

You could use 'IPE' (the "extensible drawing editor", http://ipe7.sourceforge.net/) to import the pdf with the pdftoipe command and typeset 'latex' text and draw vector graphics on it and save it as pdf.

Possible drawback: I admit that I'm not sure what it would do to text already included in the pdf. If the text is recognised, it will be typeset as latex "boxes", which might change the typeface etc. That might also depend on the pdf you want to import.