Skip to content

Instantly share code, notes, and snippets.

@kou
Created July 4, 2012 12:46
Show Gist options
  • Save kou/3047154 to your computer and use it in GitHub Desktop.
Save kou/3047154 to your computer and use it in GitHub Desktop.
split wide pages in sanders.pdf
#!/usr/bin/env ruby
require "poppler"
output_width = 378
output_height = 550
Cairo::PDFSurface.new("output.pdf", output_width, output_height) do |surface|
Cairo::Context.new(surface) do |context|
ARGV.each do |file|
pdf = Poppler::Document.new(file)
pdf.each_with_index do |page, i|
width, height = page.size
if width > output_width
context.save do
context.translate(-width / 2, 0)
context.render_poppler_page(page)
end
context.show_page
end
context.render_poppler_page(page)
context.show_page
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment