How to combine small pages of varying size to A4

I have about 80 PDF pages, all of which have width of 8.27 inches ( A4 width), but the height varies - e.g. some are 4" tall, others are 2.5" tall - there is no standard height. Let me call them snippets. I am looking to combine them so that they can fit into A4 size pages.

I have come across some utilities like nup or pdfnup but these all assume that the pages to be combined are of identical size ( say A5, to be combined into A4) . I don't care about the order of the pages, but I need to make sure that these snippets don't get cut off (or spill over into the next page) when combined. Think of it like how one would handle pasting snippets in a scapbook. If a snippet fits into a A4 page, I add to the page (no rotation etc). If some space gets left on the page, I can add another snippet that can fit in the space available. If not, I can use another page. However, the snippet must not get cut or spillover to another page.

I doubt if there is any utility/command that can do it automatically. I can work by adding snippets manually one by one - I am just looking for a suggestion on how to do it, or just help me get started.

• It looks like an NP problem. – Money Oriented Programmer Mar 30 '18 at 5:14
• Have you looked at the package pdfpages? – remco Mar 30 '18 at 5:17
• An optimal solution could be difficult but checking a list of graphics and adding the snippets to a page can be easily done with expl3 and includegraphics. – Ulrike Fischer Mar 30 '18 at 7:10
• You could try Prof Sturm's 'incgraph' package: ctan.org/pkg/incgraph. – Ross Mar 30 '18 at 10:25

If I execute

for i in /usr/local/texlive/2017/texmf-dist/tex/latex/mwe/*.pdf; do echo '\begin{center}\includegraphics{'basename \$i'}\end{center}';done > list.tex


in a (bash) command window then I get a document list.tex that looks like

\begin{center}\includegraphics{example-grid-100x100bp.pdf}\end{center}
\begin{center}\includegraphics{example-grid-100x100pt.pdf}\end{center}
\begin{center}\includegraphics{example-image.pdf}\end{center}
\begin{center}\includegraphics{example-image-10x16.pdf}\end{center}
\begin{center}\includegraphics{example-image-16x10.pdf}\end{center}
\begin{center}\includegraphics{example-image-16x9.pdf}\end{center}
\begin{center}\includegraphics{example-image-1x1.pdf}\end{center}
\begin{center}\includegraphics{example-image-4x3.pdf}\end{center}
\begin{center}\includegraphics{example-image-9x16.pdf}\end{center}
\begin{center}\includegraphics{example-image-a.pdf}\end{center}
\begin{center}\includegraphics{example-image-a3.pdf}\end{center}
\begin{center}\includegraphics{example-image-a3-landscape.pdf}\end{center}
\begin{center}\includegraphics{example-image-a4.pdf}\end{center}
\begin{center}\includegraphics{example-image-a4-landscape.pdf}\end{center}
\begin{center}\includegraphics{example-image-a4-numbered.pdf}\end{center}
\begin{center}\includegraphics{example-image-a5.pdf}\end{center}
\begin{center}\includegraphics{example-image-a5-landscape.pdf}\end{center}
\begin{center}\includegraphics{example-image-b.pdf}\end{center}
\begin{center}\includegraphics{example-image-c.pdf}\end{center}
\begin{center}\includegraphics{example-image-golden.pdf}\end{center}
\begin{center}\includegraphics{example-image-golden-upright.pdf}\end{center}
\begin{center}\includegraphics{example-image-letter.pdf}\end{center}
\begin{center}\includegraphics{example-image-letter-landscape.pdf}\end{center}
\begin{center}\includegraphics{example-image-letter-numbered.pdf}\end{center}


then I just need a file

\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}

\input{list}
\end{document}


which produces the following. Obviously the list.tex file could be hand edited to re-order or scale the images as required.

The first four pages look like:

which is a bit of a mess, but you said your pdfs all have the same width so it should work better.

• This worked very well. Thanks very much for the help ! The only modification I had to make was to use \usepackage[margin=0pt]{geometry} and it all fitted very nicely! – sunslick Apr 1 '18 at 1:00