Skip to content

Instantly share code, notes, and snippets.

@Pablo-Merino
Last active August 29, 2015 14:10
Show Gist options
  • Save Pablo-Merino/1d09318952d55411e845 to your computer and use it in GitHub Desktop.
Save Pablo-Merino/1d09318952d55411e845 to your computer and use it in GitHub Desktop.
Some scripts I wrote to help me in cutting and compressing a bunch of PDFs
require 'ruby-progressbar'
files = (1..10).to_a
dir = "./" # DIRECTORY WHERE THE PDFS ARE KEPT (the PDFs have to be named pdf-#.pdf)
progressbar = ProgressBar.create(:format => '%a %bᗧ%i %p%% %t', :progress_mark => ' ', :remainder_mark => '・', :starting_at => 0, :total => 21)
files.each do |i|
`pdf2ps pdf-#{i}.pdf pdf-#{i}.ps`
progressbar.increment
`ps2pdf pdf-#{i}.ps pdf-compressed-#{i}.pdf`
progressbar.increment
end
`rm *.ps`
progressbar.increment
require 'ruby-progressbar'
file = "./some.pdf"
base = File.dirname(file)
pages = [ # PAGES ARRAY - IT INDICATES THE FIRST AND THE LAST PAGE WHERE THE PDF WILL BE CUT
[17, 283],
[284, 618],
[620, 805],
[806, 952],
[954, 1113],
[1114, 1312],
[1314, 1407],
[1408, 1496],
[1498, 1635],
[1637, 1672]
]
progressbar = ProgressBar.create(:format => '%a %bᗧ%i %p%% %t', :progress_mark => ' ', :remainder_mark => '・', :starting_at => 0, :total => pages.count)
pages.each_with_index do |p, i|
`pdftk #{file} cat #{p[0]}-#{p[1]} output #{base}/cut-#{i+1}.pdf`
progressbar.increment
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment