使用时此处提供其他建议要在 PDF 的每一页上都放置水印\includepdf
,我想改变每页上的水印位置。一个非常费力的解决方案是一次包含一页 PDF(参见“这有效”部分)。我希望使用这个巧妙的“列表即队列”想法将所有坐标排队,然后从中弹出pdfpages
pagecommand
每个页面中弹出它们(参见“这不起作用”部分;需要注释掉“这起作用”才能完成)。
不幸的是,我对底层机制的理解现在让我失望了:错误Missing \endcsname inserted
对我来说完全不透明。我猜\el{}
弹出坐标的宏不能在我使用它的上下文中使用;如果能给出修复建议,我将不胜感激。
需要两个支持文档;我建议获取 PNG 水印图像alpha_noset.png
:
wget https://www.imagemagick.org/Usage/masking/alpha_noset.png
.. 并复制您手边的任何两页或更多页的 PDF inclusion.pdf
。
\documentclass[10pt,a4paper]{letter}
\usepackage{tikz} % Watermark overlay
\usepackage{pdfpages} % Multi-page PDF inclusions
\usepackage{graphicx} % Graphical inclusions
\usepackage{xparse}
% Pull values out of a queue, from https://tex.stackexchange.com/questions/230618/iterator-like-command-where-each-use-expands-to-an-item-from-list-defined-earli
\ExplSyntaxOn
\NewDocumentCommand{\deflist}{O{,}m}
{
\seq_set_split:Nnn \l_narebski_list_seq { #1 } { #2 }
}
\NewDocumentCommand{\el}{}
{
\seq_item:Nn \l_narebski_list_seq { 1 }
\seq_pop_left:NN \l_narebski_list_seq \l_narebski_waste_tl
}
\seq_new:N \l_narebski_list_seq
\tl_new:N \l_narebski_waste_tl
\ExplSyntaxOff
\signature{x}
\address{Etc.}
\begin{document}
\begin{letter}{To whom it may concern,}
\opening{Dear sir/madam,}
Really.
\closing{Yours sincerely,}
\newpage
\pagenumbering{gobble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This works: include PDF one page at a time, repositioning the
% watermark individually for each page.
% Integration of tikzpicture to every \includepdf taken from https://tex.stackexchange.com/questions/12838/can-i-add-tikzpictures-to-pages-included-with-pdfpages
\setkeys{pdfpages}{pagecommand={
\begin{tikzpicture}[remember picture, overlay]
\node[inner sep=0pt] at (\atx,\aty) {%
\includegraphics[width=8cm,angle=\ata]{alpha_noset.png}%
};%
\end{tikzpicture}
}}
% Co-ordinates are x=\atx, y=\aty and rotation angle=\ata.
\newcommand{\atx}{11} \newcommand{\aty}{3} \newcommand{\ata}{15}
\includepdf[pages={1}]{inclusion.pdf}
\renewcommand{\atx}{-2} \renewcommand{\aty}{-18} \renewcommand{\ata}{90}
\includepdf[pages={2}]{inclusion.pdf}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This doesn't, but I'd prefer it: queue up list of watermark co-
% ordinates and pop 'em off as needed.
% Here we line up the list of co-ordinates; in normal text, \el{}
% would retrieve them, one at a time (I could say "first: \el{},
% second: \el{}, third: \el{}", etc.). Within the pdfpages pagecommand,
% \el{} causes an error instead.
\deflist{11,3,15,-2,-18,90} % Same sequence of atx,aty,ata values as above.
\setkeys{pdfpages}{pagecommand={
\begin{tikzpicture}[remember picture, overlay]
\node[inner sep=0pt] at (\el{},\el{}) {%
\includegraphics[width=8cm,angle=\el{}]{alpha_noset.png}%
};%
\end{tikzpicture}
}}
%% COMMENT/UNCOMMENT THE NEXT LINE TO SUPPRESS/GENERATE THE FAIL:
\includepdf[pages={1,2}]{inclusion.pdf}
\end{letter}
\end{document}
答案1
\seq_pop_left:NN
在此上下文中,您不能使用不可扩展的命令。相反,您可以使用\seq_pop_left:NN
先将对象提取到新宏中,然后在命令中使用这个新宏\node
。
这不会给出预期的结果,因为你将其定义\l_narebski_list_seq
为本地的。因此 LaTeX 将始终使用第一个值,因为“pop”在当前组之后不再可见。你可以改用全局序列:
\documentclass[10pt,a4paper]{letter}
\usepackage{tikz} % Watermark overlay
\usepackage{pdfpages} % Multi-page PDF inclusions
\usepackage{graphicx} % Graphical inclusions
\usepackage{xparse}
% Pull values out of a queue, from https://tex.stackexchange.com/questions/230618/iterator-like-command-where-each-use-expands-to-an-item-from-list-defined-earli
\ExplSyntaxOn
\NewDocumentCommand{\deflist}{O{,}m}
{
\seq_gset_split:Nnn \g_narebski_list_seq { #1 } { #2 }
}
\NewDocumentCommand{\el}{m}
{
\seq_gpop_left:NN \g_narebski_list_seq #1
}
\seq_new:N \g_narebski_list_seq
\ExplSyntaxOff
\signature{x}
\address{Etc.}
\begin{document}
\begin{letter}{To whom it may concern,}
\opening{Dear sir/madam,}
Really.
\closing{Yours sincerely,}
\newpage
\pagenumbering{gobble}
\deflist{11,3,15,-2,-18,90} % Same sequence of atx,aty,ata values as above.
\setkeys{pdfpages}{pagecommand={
\begin{tikzpicture}[remember picture, overlay]
\el\atx \el\aty \el\ata
\node[inner sep=0pt] at (\atx,\aty) {%
\includegraphics[width=8cm,angle=\ata]{alpha_noset.png}%
};%
\end{tikzpicture}
}}
\includepdf[pages={1,2}]{tittoc.pdf}
\end{letter}
\end{document}