使用 pdfpages 時變更頁面順序

使用 pdfpages 時變更頁面順序

考慮以下範例。

文件: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如何更改from中的頁面順序

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另一頁上) ,然後它會列印具有更多頁面的剩餘部分。頁)。

\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 中可能會更有效。http://www.planetpdf.com/developer/article.asp?ContentID=colating_pdfs_using_javascrip&rh%20s_fa

或此線上服務 https://www.sejda.com/en/alternate-mix-pdf

相關內容