Skip to content

Instantly share code, notes, and snippets.

@kou
Created October 28, 2014 13:20
Show Gist options
  • Save kou/0600a16c7b7f519d49ef to your computer and use it in GitHub Desktop.
Save kou/0600a16c7b7f519d49ef to your computer and use it in GitHub Desktop.
Rabbit theme to keep ratio in PDF
set_background("black")
match(SlideElement) do |slides|
slides.each do |slide|
raw_page = slide.instance_variable_get(:@page).instance_variable_get(:@page)
width, height = raw_page.size
width_ratio = canvas.width.to_f / width.to_f
height_ratio = canvas.height.to_f / height.to_f
unless width_ratio == height_ratio
if width_ratio > height_ratio
width_margin = canvas.width - (width * height_ratio)
slide.margin_left = width_margin / 2
slide.margin_right = width_margin / 2
else
height_margin = canvas.height - (height * width_ratio)
slide.margin_top = height_margin / 2
slide.margin_bottom = height_margin / 2
end
end
end
end
include_theme("pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment