2

using pdfpages as a quick and dirty pdf annotation tool to fill in a pdf based form. I do this often and am really keen to try and stick to a linux environment.

There are a lot of entries so I'd like to use a macro to summarize the code

\AddToShipoutPictureFG{\put(x_coord,y_coord){content}} command with a macro. I've tried lots of variants on the \def below but keep getting errors. Any thoughts very appreciated. (including any other routes to take with this)

An MWE looks a little like the following with somepdf in the \includepdf command replaced by the pdf form in question.

\documentclass[10pt]{article} 
\usepackage{grffile} 
\usepackage{eso-pic} 
\usepackage{pdfpages}

\def\pd(#1,#2,#3){\AddToShipoutPictureFG{\put(#1,#2)\expandafter{#3}}}

\begin{document}
\AddToShipoutPictureFG{\put(35,555){\large X}}
\pd(150,150,{Rhubarb and crumble})
\includepdf[pages=1-1]{"/home/me/somepdf"}
\end{document}

1 Answers1

2

Your current definition of \pd includes an incorrect usage of \put. Put is defined to take 3 arguments in a specific delimited form (from latex.ltx):

\long\gdef\put(#1,#2)#3{%
  \@killglue\raise#2\unitlength
  \hb@xt@\z@{\kern#1\unitlength #3\hss}%
  \ignorespaces}

Using \pd(<x>,<y>,<stuff>) expands to

\AddToShipoutPictureFG{\put(<x>,<y>)\expandafter{<stuff>}}

where \put grabs <x> as #1, <y> as #2 and \expandafter as #3. Perhaps the following definition of \pd is what you're after:

\def\pd(#1,#2,#3){% \pd(<x>,<y>,<stuff>)
  \AddToShipoutPictureFG{\put(#1,#2){#3}}}

which will appropriately pass #3 to \put.

Here's a complete minimal example showing the difference:

enter image description here

\documentclass{article} 
\usepackage{eso-pic,pdfpages}% http://ctan.org/pkg/{eso-pic,pdfpages}
\makeatletter
\def\pdA(#1,#2,#3){\AddToShipoutPictureFG{\put(#1,#2)\expandafter{#3}}}
\def\pdB(#1,#2,#3){\AddToShipoutPictureFG{\put(#1,#2){#3}}}
\makeatother
\begin{document}
\AddToShipoutPictureFG{\put(35,555){\large X}}
\pdA(150,150,{\color{red}Rhubarb and crumble})
\pdB(150,150,{\color{green}Rhubarb and crumble})
\pdB(100,100,{Crumble topping})
\includepdf[pages=1-1]{lipsum50}
\end{document}
Werner
  • 603,163