How to merge multiple PDF files onto one page with pdftk?

116,984

Solution 1

I do not know if pdftk can do this, but pdfjam can. It can be installed on debian or derivates with sudo apt install texlive-extra-utils. Then you can do:

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

It puts 2 pages on one page side by side. With --nup 1x2 --no-landscapeyou can put two pages on one page on top of each other.

Solution 2

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

Solution 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

Solution 4

you can use montage from ImageMagick

$ montage *.pdf merged.pdf

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

Share:
116,984

Related videos on Youtube

user2251503
Author by

user2251503

Bioinformaticist, hobbyist iPhone developer, pug caregiver

Updated on September 18, 2022

Comments

  • user2251503
    user2251503 over 1 year

    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?

  • user2251503
    user2251503 over 12 years
    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.
  • szemek
    szemek over 12 years
    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.
  • Benedikt Köppel
    Benedikt Köppel about 11 years
    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
  • evilsoup
    evilsoup over 10 years
    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.
  • Admin
    Admin over 7 years
    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.
  • Jeremy Davis
    Jeremy Davis over 6 years
    upvoted this answer - only because downvotes without a comment are not cool IMO!
  • Jonathan Y.
    Jonathan Y. about 6 years
    If you wanted no auto-scaling of pages (mine stretches output to fill a4 by default), use --noautoscale true
  • Nik
    Nik over 5 years
    Downvoted because the subject says "with pdftk". Your answer is maybe not off topic, but clearly not what the questioner is looking for.
  • Zimba
    Zimba over 4 years
    This does NOT answer the question, which is asking about pdftk
  • stephanmg
    stephanmg almost 4 years
    I agree with @Nik's conjecture.
  • Christian Herenz
    Christian Herenz over 2 years
    Absolutely not an answer to the question. The adjective tiled is defined as "arrange without overlap".
  • Michel de Ruiter
    Michel de Ruiter over 2 years
    This does not tile anything onto one page.
  • Gunther Schadow
    Gunther Schadow over 2 years
    @ChristianHerenz it's not the reason why the answer is not good. It could be a step to the solution. But turns out that it does nothing other than concatenating the pages.