35

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?

29

I tested this today:

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

It puts 2 pages on one page.

  • works under windows as well (with wsl) sudo apt-get install pdfjam – jan-glx Mar 16 '17 at 11:51
  • 4
    if you wanted to glue pages vertically, use --nup 1x2 --no-landscape – jan-glx Mar 16 '17 at 11:55
  • If you wanted no auto-scaling of pages (mine stretches output to fill a4 by default), use --noautoscale true – Jonathan Y. Mar 12 '18 at 14:14
  • 1
    The question is asking about pdftk, not pdfjam. This does not answer the question; it's a suggestion to find an alternative – Zimba Sep 28 at 12:06
6

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.

4

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

3

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

#!/usr/bin/ruby

latexhead = <<'EOF'
\documentclass{article}
\usepackage[pdftex]{graphicx}
\usepackage[margin=0.1in]{geometry}
\usepackage{pdfpages}
\begin{document}
EOF
latextail = <<'EOF'
\end{document}
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]}}"
  end
  puts "\\end{figure}"
end
puts latextail
1
+25

you can use montage from ImageMagick

$ montage *.pdf merged.pdf

see also http://www.imagemagick.org/script/montage.php

  • 13
    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: superuser.com/a/479767/149568 – Benedikt Köppel Feb 20 '13 at 13:00
  • 1
    This does NOT answer the question, which is asking about pdftk – Zimba Sep 28 at 12:14
0

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.

Example:
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.

  • 1
    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
0

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:

    #!/bin/bash
#
# 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
fi
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
  fi
done
cat >"$FILE.tex" <<EOF
\documentclass{article}%
\usepackage{pdfpages}%
\usepackage{grffile}%
\listfiles%
\begin{document}%
%\tableofcontents%
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
      done
    done
  done
done >>"$FILE.tex"
echo "\end{document}%" >>"$FILE.tex"
echo "Sourcecode to PDF directly [J/n]"
read -r ANSWER
case "$ANSWER" in
[JjYy]) ;;
*) exit 0 ;;
esac
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: http://www.listserv.dfn.de/cgi-bin/wa?A2=ind1201&L=tex-d-l&T=0&P=10771

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

Regards, Alexander

0

This link: http://www.verypdf.com/wordpress/201302/how-to-combine-4-page-pdf-into-1-page-pdf-file-to-save-ink-and-papers-34505.html shows VeryPDF PDF Stitcher can do the job vertically or sideways. Download at: http://www.verypdf.com/app/pdf-stitch/index.html

-1
  1. Save pages wanted into a pdf doc with something like Acrobat Pro.

  2. Print document using the multiple pages to a page feature, back to a pdf document.

Multiple pages to a single page. :-)

  • I see your answer is downvoted without a comment. That's not cool, but there are certainly ways to improve your answer. Improve its grammar, add a description to the top as to why you are doing this, etc. – user477799 Feb 13 '17 at 7:49
  • upvoted this answer - only because downvotes without a comment are not cool IMO! – Jeremy Davis Nov 14 '17 at 0:45
  • 1
    Downvoted because the subject says "with pdftk". Your answer is maybe not off topic, but clearly not what the questioner is looking for. – Nik Dec 18 '18 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.