使用 pdfpages 编辑 pdf 时 \AddToPictureShipoutFG 的宏

使用 pdfpages 编辑 pdf 时 \AddToPictureShipoutFG 的宏

用作pdfpages快速而简单的 PDF 注释工具来填写基于 PDF 的表单。我经常这样做,并且非常热衷于尝试并坚持使用 Linux 环境。

由于条目很多,所以我想使用宏来总结代码

\AddToShipoutPictureFG{\put(x_coord,y_coord){content}}命令与宏。我尝试了下面 \def 的许多变体,但总是出错。任何想法都非常感谢。(包括任何其他可采取的路线)

MWE 看起来有点像下面的命令,其中的somepdf命令\includepdf被有问题的 pdf 表单替换。

\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

您当前的 定义\pd包含 的错误用法\put。Put 被定义为采用特定分隔格式的 3 个参数(来自latex.ltx):

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

使用\pd(<x>,<y>,<stuff>)扩展为

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

其中\put抓取<x>#1<y>#2\expandafter#3。也许以下的定义\pd就是您所追求的:

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

它将适当地传递#3\put

这是一个完整的最小示例,显示了差异:

在此处输入图片描述

\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}

相关内容