Skip to content

Instantly share code, notes, and snippets.

@User4574
Last active June 23, 2023 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save User4574/384551daf04d590c057421edd4a7063a to your computer and use it in GitHub Desktop.
Save User4574/384551daf04d590c057421edd4a7063a to your computer and use it in GitHub Desktop.
Page order to make (or pdfjam command to turn a pdf file into) 4-up double-sided brochure ordered pages (to make two A6 folia per A4 page)
#!/usr/bin/env ruby
n = ARGV.shift.to_i
m = n
m = ((m / 8) + 1) * 8 if m % 8 != 0
p = (1..n).map(&:to_s) + ["{}"] * (m - n)
o = []
until p.empty? do
t1 = []
t2 = []
t1.push(p.pop)
t1.push(p.shift)
t2.push(p.shift)
t2.push(p.pop)
t1.push(p.pop)
t1.push(p.shift)
t2.push(p.shift)
t2.push(p.pop)
o += t1
o += t2
end
f = ARGV.shift
if f.nil?
puts o.join(?,)
else
puts "pdfjam --nup 2x2 -o #{File.basename(f, ".*")}-book.pdf #{f} #{o.join(?,)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment