module ResumeTools::Renderer::PDF
Constants
- DATE_FORMAT
- FONT_DIR
- FONT_SIZES
- MARGINS
Public Instance Methods
drawline(pdf)
click to toggle source
# File lib/resumetools/resume/pdf.rb, line 146 def drawline(pdf) pdf.stroke do pdf.line_width = 0.25 pdf.stroke_color("000000") pdf.horizontal_rule end end
render_pdf(opts={}) { |result| ... }
click to toggle source
Render to PDF
# File lib/resumetools/resume/pdf.rb, line 46 def render_pdf(opts={}, &blk) default_font = opts.delete(:default_font) || "SourceSansPro" pdf = Prawn::Document.new( :info => {}, :top_margin => MARGINS[0].in, :left_margin => MARGINS[1].in, :bottom_margin => MARGINS[2].in, :right_margin => MARGINS[3].in ) pdf.font_families.update( "SourceSansPro" => { :normal => File.expand_path("SourceSansPro-Regular.ttf", FONT_DIR), :bold => File.expand_path("SourceSansPro-Semibold.ttf", FONT_DIR), :italic => File.expand_path("SourceSansPro-It.ttf", FONT_DIR), :bold_italic => File.expand_path("SourceSansPro-SemiboldIt.ttf", FONT_DIR) } ) # Set default font pdf.font(default_font, :style => :normal, :size => FONT_SIZES[:default], :kerning => true) # Name pdf.text(self.full_name, style: :bold, size: FONT_SIZES[:header], align: :center) # Contact info self.header_lines.each do |line| pdf.text(line, { align: :center }) end pdf.pad_bottom 10 do end drawline(pdf) pdf.pad_bottom 0 do end # Sections self.sections.each_with_index do |section, index| pdf.pad_top(20) do # Section title pdf.text section.title, :style => :bold, :size => FONT_SIZES[:section] # Section paragraph unless section.para.blank? pdf.span(pdf.bounds.width - 10, :position => 10) do pdf.pad_top(5) { pdf.text section.para, :size => FONT_SIZES[:para] } end end # Section items unless section.items.empty? pdf.table(section.items.map { |item| [" •", item.text] }, :cell_style => { :borders => [] }) # , cell_style: { # :font_size => FONT_SIZES[:item], # :border_style => :none, # :border_color => "ffffff", # :vertical_padding => 4, # :horizontal_padding => 0, # :align => { 0 => :left, 1 => :left }, # :column_widths => { 0 => 20, 1 => 420 } # } end # Periods section.periods.each do |period| pdf.pad_top(5) do # Period title pdf.pad_top(5) { pdf.text period.title, :style => :bold, :size => FONT_SIZES[:period] } # Period details pdf.pad_top(5) do pdf.text(period.line, :size => FONT_SIZES[:default]) end # Period items unless period.items.empty? pdf.table(period.items.map { |item| [" •", item.text] }, :cell_style => { :borders => [] }) end end end end end if blk result = { pages: pdf.page_count } yield result end pdf.render end