Here is a simpler solution that does not need two separate compilations of two separate documents:
- Intercept every page when it is shipped out,
- add it to a box and
- 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}
pdfpagespackage. – Iacobus1983 Sep 12 '23 at 10:38