Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a range of PDF files 1.pdf, 2.pdf, etc. that I would like to merge into one file, with all the PDFs tiled on one page.

Currently, I have tried pdftk to merge these files, but they are put on separate pages:

pdftk 1.pdf 2.pdf ... cat output merged.pdf

Is there a way to, instead, tile the individual PDF files into one master page on merged.pdf?

share|improve this question
In cases where using a GUI app is OK, a good alternative is – reinierpost Jan 31 '12 at 11:12

I tested this today:

pdfjam Page1.pdf Page2.pdf --nup 2x1 --landscape --outfile Page1+2.pdf

It puts 2 pages on one page.

share|improve this answer

The pdfLaTeX based pdfnup might work for you. If you have lots of pdf-files you may need to make a long pipe of pdfjam or run it several times.

There is also pdfnup in python.

share|improve this answer

you can use montage from ImageMagick

$ montage *.pdf merged.pdf

see also

share|improve this answer
ImageMagick montage will not handle vectorized images and fonts properly. As a result, the output from the montage command might look blurry. See also the explanation here: – Benedikt Köppel Feb 20 '13 at 13:00

Not sure what you mean by tiled on one page. I was looking for a way to merge multiple PDFs on one page - on top of another. This can be done with pdftk like this:

pdftk foreground.pdf background background.pdf output merged.pdf

share|improve this answer

This script will tile the pdf pages for you. Change the slice to what you need per page.


latexhead = <<'EOF'
latextail = <<'EOF'

pages = %x[pdfinfo #{ARGV[0]}].split(/\n/).select{|x| x=~ /Pages:/}[0].split(/\s+/)[1].to_i
puts latexhead
s = (1..pages).each_slice(4).to_a
s.each do |a|
  puts "\\begin{figure}"
  a.each do |p|
    puts "\\includegraphics[page=#{p},scale=0.4,width=.5\\textwidth]{#{ARGV[0]}}"
  puts "\\end{figure}"
puts latextail
share|improve this answer

If filenames are in "system specific" order, then pdftk *.pdf cat output merged.pdf should work just fine.

Here is what I mean by "system specific" order.

I've got 3 files on my Ubuntu 11.04: 1.pdf, 2.pdf, 10.pdf
Files are merged in order: 10.pdf 1.pdf 2.pdf (ls -l returned the same order as in merged file)

Safest naming convention: 0001.pdf, 0002.pdf, etc.

share|improve this answer
As I stated, this command creates a multi-page PDF. As stated in my question, I am looking for the method of using pdftk to make a one-page PDF that contains input PDFs as tiles. – Alex Reynolds Dec 11 '11 at 9:35
Combine my answer with @micke's. I haven't checked whether pdfnup can take name with wildcard (*.pdf) as argument, but you can use pdf generated by pdftk. Check pdfnup or pdfjam with --nup option. – szemek Dec 11 '11 at 16:49
Unless you quote them, wildcards like * are expanded by the shell you're using. pdfnup doesn't ever see *.pdf, instead it sees a list of every file in the working directory with filenames ending in .pdf. – evilsoup Aug 27 '13 at 16:11

If you've got a large number of PDFs in one folderstructure, and you've got a TeX-Installation, this script puts all the PDFs recursivly into one large file:

# pdfdir OUTPUT_FILE
# produces one big PDF file of all PDF files in .
if [ $# -ne 1 ] || [ -z "$1" ]; then
  echo "Syntax: pdfdir OUTPUT_FILE"
  exit 1
FILE="$(echo "$1"|sed -e 's/\.\(pdf\|tex\)$//')"
for F in "$FILE" "$FILE.tex" "$FILE.pdf" "$FILE.aux" "$FILE.log" ; do
  if [ -e "$F" ]; then
    echo "$F exists already."
    exit 2
cat >"$FILE.tex" <<EOF
# helper functions
exist_pdf_files () {
  [ $(find -L "$1" -name \*.pdf -o -name \*.PDF -type f 2>/dev/null|wc -l) -eq 0 ] && return 1
  return 0
list_directories () {
  find -L "$1" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort
list_pdf_files () {
  # version with " around filenames:
  #find -L "$1" -maxdepth 1 -mindepth 1 -name \*.pdf -o -name \*.PDF -type f 2>/dev/null | sort | \
  #  sed -e 's/^/\\includepdf[pages=-]{"/; s/$/"}%/'
  # version without " around filenames:
  find -L "$1" -maxdepth 1 -mindepth 1 -name \*.pdf -o -name \*.PDF -type f 2>/dev/null | sort | \
    sed -e 's/^/\\includepdf[pages=-]{/; s/$/}%/'
tex_headline () {
    echo "$1" | sed -e 's/_/\\_/g'
# current folder (lefel 0):
list_pdf_files . >>"$FILE.tex"
# Bearbeite Ebene 1:
list_directories . | while read -r DIR1; do
  # Are there PDFs in folders below that level?
  exist_pdf_files "$DIR1" || continue
  # Yes ...
  tex_headline "\section{${DIR1##*/}}%"
  # those:
  list_pdf_files "$DIR1"
  # Level 2:
  list_directories "$DIR1" | while read -r DIR2; do
    exist_pdf_files "$DIR2" || continue
    tex_headline "\subsection{${DIR2##*/}}%"
    list_pdf_files "$DIR2"
    # Level 3:
    list_directories "$DIR2" | while read -r DIR3; do
      exist_pdf_files "$DIR3" || continue
      tex_headline "\subsubsection{${DIR3##*/}}%"
      list_pdf_files "$DIR3"
      # Level 4:
      list_directories "$DIR3" | while read -r DIR4; do
        exist_pdf_files "$DIR4" || continue
        tex_headline "\paragraph{${DIR4##*/}}%"
        list_pdf_files "$DIR4"
        # Level 5:
        list_directories "$DIR4" | while read -r DIR5; do
          exist_pdf_files "$DIR5" || continue
          tex_headline "\subparagraph{${DIR5##*/}}%"
          list_pdf_files "$DIR5"
done >>"$FILE.tex"
echo "\end{document}%" >>"$FILE.tex"
echo "Sourcecode to PDF directly [J/n]"
read -r ANSWER
case "$ANSWER" in
[JjYy]) ;;
*) exit 0 ;;
pdflatex "$FILE"
[ $? -eq 0 ] && rm -f "$FILE.aux" "$FILE.log" "$FILE.tex"

I have not written that code, I've got it from a discussion here:

It is very usefull. I've translated some German comments into English.

Regards, Alexander

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .