0

I have a rather long document that normally renders as two pages. Now, I want a single page PDF document to be generated instead. In other words, I want a PDF of A4x2 size. How would you do it?

It's possible to do it after compilation: https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf

yegor256
  • 12,021
  • 1
    Note: A4 x 2 = A3 – Paul Gaborit Sep 12 '23 at 05:52
  • 1
    @PaulGaborit not if joined on the short side, which is I think required here – David Carlisle Sep 12 '23 at 06:39
  • 1
    @yegor256 Do you want to have the two pages joined on a single sheet, without changing the typesetting? On which side would you like the two A4 to be joined? A3 landscape orientation, or a sheet 21 x 59,4 cm? Anyway, have a look to pdfpages package. – Iacobus1983 Sep 12 '23 at 10:38
  • @lacobus1983 I expect my pages to go one after another in a long vertical document. If there would be five pages in the document, I want them to rendered as a very tall vertical PDF. – yegor256 Sep 12 '23 at 10:42
  • Somewhat related: https://tex.stackexchange.com/questions/244348/make-only-one-page-for-each-chapter You can use includegraphics to copy one page at a time. – John Kormylo Sep 12 '23 at 13:15

2 Answers2

2

To illustrate my comment:

\documentclass{standalone}
\usepackage{graphicx}

\newcommand{\pages}{6}% number of pages \newcommand{\filename}{pecha.pdf}% filename of document

\newcounter{pdfpage} \newsavebox{\tempbox} \savebox{\tempbox}{\includegraphics[page=1]{\filename}}% get width of document

\begin{document} \begin{minipage}{\wd\tempbox} \loop\ifnum\value{pdfpage}<\pages\relax \stepcounter{pdfpage}% \includegraphics[page=\thepdfpage]{\filename}\par \repeat \end{minipage} \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

Here is a simpler solution that does not need two separate compilations of two separate documents:

  1. Intercept every page when it is shipped out,
  2. add it to a box and
  3. shipout the box at the end of the document.

The package AtBegShi makes the first step very easy, and the second step can be taken care of with the normal (plain) primitives.

% PACKAGE CODE

\RequirePackage{atbegshi} \RequirePackage{luatex85}

\newbox \fulldocument

\AtBeginShipout{% \global\setbox\fulldocument=\vbox\bgroup % previous pages \unvbox\fulldocument % a line between pages \hrule width \pdfpagewidth % the current page \vbox to \pdfpageheight\bgroup % we have to position it like tex does \vskip \dimexpr \pdfvorigin + \voffset \moveright \dimexpr \pdfhorigin + \hoffset \box\AtBeginShipoutBox \vss \egroup \egroup \AtBeginShipoutDiscard}

\AtEndDocument{\par\break % spacing has already been applied manually \pdfhorigin = 0pt \pdfvorigin = 0pt \hoffset = 0pt \voffset = 0pt % set the new page height \pdfpageheight = \ht\fulldocument % output the full page \AtBeginShipoutOriginalShipout \box\fulldocument}

% DOCUMENT CODE

\documentclass{article}

\begin{document}

Page 1 \newpage Page 2 \newpage Page 3

\end{document}

renkema
  • 431
  • 2
  • 8