![使用 pdfpages 时更改页面顺序](https://linux22.com/image/353390/%E4%BD%BF%E7%94%A8%20pdfpages%20%E6%97%B6%E6%9B%B4%E6%94%B9%E9%A1%B5%E9%9D%A2%E9%A1%BA%E5%BA%8F.png)
考虑以下示例。
文件:B.tex
\documentclass[
12pt,
landscape
]{article}
\usepackage[
a6paper
]{geometry}
\usepackage{multido}
\newenvironment{navn}{%
\setlength{\topskip}{0pt}%
\centering
\vspace*{\fill}%
\nointerlineskip
\Huge
% \sbox0{Front}%
% \showthe\ht0
}{%
\par
\vspace*{\fill}%
% \setlength{\showboxdepth}{\maxdimen}%
% \setlength{\showboxbreadth}{\maxdimen}%
% \tracingonline=1 %
% \showlists
}
\pagestyle{empty}
\begin{document}
\multido{\i = 1+1}{16}{%
\begin{navn}
Front
\end{navn}
\newpage}
\end{document}
文件:C.tex
\documentclass[
12pt,
landscape
]{article}
\usepackage[
a6paper
]{geometry}
\usepackage{multido}
\newenvironment{navn}{%
\setlength{\topskip}{0pt}%
\centering
\vspace*{\fill}%
\nointerlineskip
\Huge
% \sbox0{XYZ}%
% \showthe\ht0
}{%
\par
\vspace{\fill}%
% \setlength{\showboxdepth}{\maxdimen}%
% \setlength{\showboxbreadth}{\maxdimen}%
% \tracingonline=1 %
% \showlists
}
\pagestyle{empty}
\begin{document}
\multido{\i = 1+1}{16}{%
\begin{navn}
\thepage
\end{navn}
\newpage}
\end{document}
文件:A.tex
\documentclass[
a4paper
]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[
nup = 2x4,
pages = -,
frame = true
]{B}
\includepdf[
nup = 2x4,
pages = -
]{C}
\end{document}
(实际上,这些文件B.tex
要大得多。)C.tex
问题
更新
如何更改页面的A.pdf
顺序
Bp1,Bp2,...,Bpn,Cp1,Cp2,...,Cpn
到
Bp1,...,Bp8,Cp1,...,Cp8,[...],Bp(n-8),...,Bpn,Cp(n-8),Cpn
对于任意 n?
也就是说,A.pdf
我只希望从 的页面B.pdf
出现在第一页,只希望从 的页面C.pdf
出现在第二页,依此类推。
答案1
我删除了以前的代码,所以这个答案符合你问题的最新编辑。
下面的代码可以完成您想要的操作(并检查和是否C.pdf
具有B.pdf
相同的页数,如果不是,则打印到页数较少的页面的最后一页(以双面方式,在B
一页上打印,C
在另一页上打印),然后打印页数较多的页面的剩余部分。它接受一个可选参数,该参数可以给出一个固定的最大页面数,而不是两个 pdf 的所有页面(尽管对于固定的最大页面数,不会检查两个 PDF 是否都有那么多页面)。
\documentclass[
a4paper
]{article}
\usepackage{pdfpages}
\newcount\maxpages
\newcount\curpage
\newcount\untilpage
\makeatletter
\newif\if@pdfdingsunbalance
\newcount\@testmaxpages
\newcommand{\@incpdfdings}[3]{\includepdf[nup=2x4,pages={#1-#2},frame=true]{#3}}
\newcommand{\incpdfdings}[3][]{%
\ifx\relax#1\relax%
\pdfximage{#2}%
\maxpages=\pdflastximagepages%
\pdfximage{#3}%
\@testmaxpages=\pdflastximagepages%
\ifnum\maxpages<\@testmaxpages%
\@pdfdingsunbalancetrue%
\def\@pdfdingsmore{#3}%
\else\ifnum\@testmaxpages<\maxpages%
\@pdfdingsunbalancetrue%
\def\@pdfdingsmore{#2}%
\maxpages=\@testmaxpages%
\fi\fi%
\else%
\maxpages=#1%
\fi%
\curpage=0%
\loop\ifnum\maxpages>\curpage%
\advance\curpage by 1%
\untilpage=\numexpr\curpage+7\relax%
\ifnum\maxpages>\untilpage\else%
\untilpage=\maxpages%
\fi%
\@incpdfdings{\the\curpage}{\the\untilpage}{#2}%
\@incpdfdings{\the\curpage}{\the\untilpage}{#3}%
\advance\curpage by 7%
\repeat%
\if@pdfdingsunbalance%
\advance\maxpages by 1%
\@incpdfdings{\the\maxpages}{}{\@pdfdingsmore}%
\fi%
}
\makeatother
\begin{document}
\incpdfdings{B.pdf}{C.pdf}
\end{document}
编辑:无论如何我都会发布错误检测(它会引发警告):
\documentclass[
a4paper
]{article}
\usepackage{pdfpages}
\newcount\maxpages
\newcount\curpage
\newcount\untilpage
\makeatletter
\newif\if@pdfdingsunbalance
\newcount\@testmaxpages
\newcommand{\@incpdfdings}[3]{\includepdf[nup=2x4,pages={#1-#2},frame=true]{#3}}
\newcommand{\incpdfdings}[3][]{%
\ifx\relax#1\relax%
\pdfximage{#2}%
\maxpages=\pdflastximagepages%
\pdfximage{#3}%
\@testmaxpages=\pdflastximagepages%
\ifnum\maxpages<\@testmaxpages%
\@pdfdingsunbalancetrue%
\def\@pdfdingsmore{#3}%
\else\ifnum\@testmaxpages<\maxpages%
\@pdfdingsunbalancetrue%
\def\@pdfdingsmore{#2}%
\maxpages=\@testmaxpages%
\fi\fi%
\else%
\maxpages=#1%
\pdfximage{#2}%
\@testmaxpages=\pdflastximagepages%
\ifnum\maxpages>\@testmaxpages%
\@latex@warning{The file #2 you wanted to be printed with
incpdfdings doesn't have enough pages to match your request in
the optional argument}%
\maxpages=\@testmaxpages%
\fi%
\pdfximage{#3}%
\@testmaxpages=\pdflastximagepages%
\ifnum#1>\@testmaxpages%
\@latex@warning{The file #3 you wanted to be printed with
incpdfdings doesn't have enough pages to match your request in
the optional argument}%
\ifnum\maxpages>\@testmaxpages%
\maxpages=\@testmaxpages%
\fi\fi%
\fi%
\curpage=0%
\loop\ifnum\maxpages>\curpage%
\advance\curpage by 1%
\untilpage=\numexpr\curpage+7\relax%
\ifnum\maxpages>\untilpage\else%
\untilpage=\maxpages%
\fi%
\@incpdfdings{\the\curpage}{\the\untilpage}{#2}%
\@incpdfdings{\the\curpage}{\the\untilpage}{#3}%
\advance\curpage by 7%
\repeat%
\if@pdfdingsunbalance%
\advance\maxpages by 1%
\@incpdfdings{\the\maxpages}{}{\@pdfdingsmore}%
\fi%
}
\makeatother
\begin{document}
\incpdfdings[60]{B.pdf}{C.pdf}
\end{document}
答案2
将两个 PDF 文件合并为一个,然后再将其添加到文档 C 中可能会更有效率。如果您习惯使用 JavaScript,此链接可能会有用:http://www.planetpdf.com/developer/article.asp?ContentID=collating_pdfs_using_javascrip&rh%20s_fa