Skip to content

Instantly share code, notes, and snippets.

@rriemann
Created January 12, 2012 12:40
Show Gist options
  • Save rriemann/1600271 to your computer and use it in GitHub Desktop.
Save rriemann/1600271 to your computer and use it in GitHub Desktop.
merge pdf files using ghostscript
#!/usr/bin/env ruby
if ARGV.first == "--help"
puts <<-EOF
usage: pdfmerge.rb SUMMARYFILE FILE1 FILE2 ...
All Files have to be pdf-Files. Requires GhostScript (gs).
Copyright 2009 Robert Riemann - licensed under GPL v2 or higher.
EOF
exit
end
begin
( ARGV.size - 1 ).times { |i|
# raise RuntimeError, ARGV[i+1] + " doesn't exist. Aborting." unless File.exists? ARGV[i+1]
raise ARGV[i+1] + " doesn't exist. Aborting." unless File.exists? ARGV[i+1]
}
rescue
STDERR.puts $!
exit 1
end
files = ARGV.join('" "')
%x[gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="#{files}"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment