如何使用 pgfpages 创建标签页

如何使用 pgfpages 创建标签页

我正在尝试使用 创建标签表pgfpages,但显然我做错了。以下是我尝试过的方法:

\documentclass{article}
\usepackage[paperwidth=2in,paperheight=2in,nohead,nofoot]{geometry}
\pagestyle{empty}

\usepackage{pgf}
\usepackage{pgfpages}

% Layout from http://www.onlinelabels.com/OL3016.htm
\pgfpagesdeclarelayout{OL3016}
{
  \edef\pgfpageoptionheight{\the\paperheight}%
  \edef\pgfpageoptionwidth{\the\paperwidth}%
  \edef\pgfpageoptionborder{0pt}%
  \edef\labelheight{2in}%
  \edef\labelwidth{2in}%
  \edef\labelmargin{0.25in}%
  \edef\labelxsep{1in}%
  \edef\labelysep{0.8333in}%
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=12,%
    last logical shipout=12,
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth,%
    current logical shipout=1,%
  }
%
  \pgfpageslogicalpageoptions{1}
  {% 
    %copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{1.25in}{1.25in}%
  }%
  \pgfpageslogicalpageoptions{2}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{4.25in}{1.25in}%
  }%
  \pgfpageslogicalpageoptions{3}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{7.25in}{1.25in}%
  }%
%
  \pgfpageslogicalpageoptions{4}
  {% 
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{1.25in}{3.25in+\labelysep}%
  }%
  \pgfpageslogicalpageoptions{5}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{1.25in+3in}{3.25in+\labelysep}%
  }%
  \pgfpageslogicalpageoptions{6}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{7.25in}{3.25in+\labelysep}%
  }%  
%  
  \pgfpageslogicalpageoptions{7}
  {% 
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{1.25in}{5.25in+2*\labelysep}%
  }%
  \pgfpageslogicalpageoptions{8}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{4.25in}{5.25in+2*\labelysep}%
  }%
  \pgfpageslogicalpageoptions{9}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{7.25in}{5.25in+2*\labelysep}%
  }%  
%  
  \pgfpageslogicalpageoptions{10}
  {% 
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{1.25in}{7.25in+3*\labelysep}%
  }%
  \pgfpageslogicalpageoptions{11}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{4.25in}{7.25in+3*\labelysep}%
  }%
  \pgfpageslogicalpageoptions{12}
  {%
    copy from=1,%
    border code=\pgfstroke,%
    border shrink=\pgfpageoptionborder,%
    resized width=\labelwidth,%
    resized height=\labelheight,%
    center=\pgfpoint{7.25in}{7.25in+3*\labelysep}%
  }%  
}


\pgfpagesuselayout{OL3016}[letterpaper]

\begin{document}

This is my label 1.\clearpage
This is my label 2.\clearpage
This is my label 3.\clearpage
This is my label 4.\clearpage
This is my label 5.\clearpage
This is my label 6.\clearpage
This is my label 7.\clearpage
This is my label 8.\clearpage
This is my label 9.\clearpage
This is my label 10.\clearpage
This is my label 11.\clearpage
This is my label 12.\clearpage
This is my label 13.\clearpage

\end{document}

我原本期望一张纸上有 12 份相同的标签(因为有这个copy from选项)。我得到的是第一页有标签 1 -- 12,第二页有标签 13 和 11 个标签 1。

可以pgfpages用来声明在每个物理页面上有 12 个相同逻辑页面副本的布局吗?

答案1

这不是答案,而是解决问题的另一种方法。我建议将所有标签绘制在一个文件中,然后使用pdfpages包帮助。

您的标签文件将是:

%----labels.tex ---------%
\documentclass{article}
\usepackage[paperwidth=2in,paperheight=2in,nohead,nofoot]{geometry}
\pagestyle{empty}
\begin{document}
\thispagestyle{empty}
This is my label 1.\clearpage
This is my label 2.\clearpage
This is my label 3.\clearpage
This is my label 4.\clearpage
This is my label 5.\clearpage
This is my label 6.\clearpage
This is my label 7.\clearpage
This is my label 8.\clearpage
This is my label 9.\clearpage
This is my label 10.\clearpage
This is my label 11.\clearpage
This is my label 12.\clearpage
This is my label 13.\clearpage
\end{document}

创建后labels.pdf,使用以下命令创建一个printlabels.tex

%----printlabels.tex----------
\documentclass[letter]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={1-13},% which labels do you want to print
    delta=.5in 0.8333in,% space between copies
    frame,% comment if don't want frames
   noautoscale,% keep original labels size
   nup=3x4,% how many labels on physical page
   duplicatepages=12 % how many copies of same label
]{labels.pdf}
\end{document}

pdflatex它,你会得到你想要的:一个 13 页的 pdf 文件,每页有 12 个标签副本。

更新:

申请赫伯特的回答您能让 LTXinputExample 的“图形”选项能够渲染多页 PDF 文件的所有页面吗?,可以将我之前的回答减少到一次处理一个文件。

filecontents包、labels.tex文件被包含printlabels.tex并被\immediate\write18{pdflatex lables.tex}命令处理。之后标签被pdfpages命令复制。

您只需更改geometry选项来修复标签大小。

\documentclass[letter]{article}

\usepackage{filecontents}
\begin{filecontents*}{mylabels.tex}
\documentclass{article}
\usepackage[paperwidth=2in,paperheight=2in,nohead,nofoot]{geometry}
\pagestyle{empty}
\begin{document}
\thispagestyle{empty}
This is my label 1.\clearpage
This is my label 2.\clearpage
This is my label 3.\clearpage
This is my label 4.\clearpage
This is my label 5.\clearpage
This is my label 6.\clearpage
This is my label 7.\clearpage
This is my label 8.\clearpage
This is my label 9.\clearpage
This is my label 10.\clearpage
This is my label 11.\clearpage
This is my label 12.\clearpage
This is my label 13.\clearpage
\end{document}
\end{filecontents*}

\immediate\write18{pdflatex mylabels.tex}

\usepackage{pdfpages}
\begin{document}
\includepdf[pages={1-13},%
    delta=.5in 0.8333in,%
    frame,%
   noautoscale,%
   nup=3x4,%
    duplicatepages=12]{mylabels.pdf}
\end{document}

相关内容