Skip to content

Instantly share code, notes, and snippets.

@tylergannon
Created October 17, 2016 04:11
Show Gist options
  • Save tylergannon/dec123f635369c92516bdc6b6505ac0d to your computer and use it in GitHub Desktop.
Save tylergannon/dec123f635369c92516bdc6b6505ac0d to your computer and use it in GitHub Desktop.
Example PDF style declaration
module Stylesheet
extend ActiveSupport::Concern
include PdfStylesheet
PAGE_BREAK_RULES = [nil, 600, 200, 200, 100, 100].freeze
MARGIN_TOP_MM = 25
MARGIN_BOTTOM_MM = 30
MARGIN_LEFT_MM = 25
MARGIN_RIGHT_MM = 25
COURIER_NEW = Rails.font_path('Courier Prime.ttf')
COURIER_BOLD = Rails.font_path('Courier Prime Bold.ttf')
included do
style :document do
margin 0
top_margin mm2pt(MARGIN_TOP_MM)
bottom_margin mm2pt(MARGIN_BOTTOM_MM)
left_margin mm2pt(MARGIN_LEFT_MM)
right_margin mm2pt(MARGIN_RIGHT_MM)
end
style :root do
font COURIER_NEW
end
style :header1 do
bottom_padding(-10)
top_padding 0
end
style :header2 do
size 20
bottom_padding 5
end
style :strong, :em do
font COURIER_BOLD
end
style :header3 do
size 15
styles [:bold]
font COURIER_NEW
top_padding 0
bottom_padding 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment