class PdfTempura::Renderer
Public Class Methods
new(template_path, pages, options = {})
click to toggle source
# File lib/pdf_tempura/renderer.rb, line 7 def initialize(template_path, pages, options = {}) @template_path = template_path @pages = pages @options = options @template_page_count = options[:template_page_count] || @pages.count end
Public Instance Methods
render() { |tempfile| ... }
click to toggle source
# File lib/pdf_tempura/renderer.rb, line 21 def render tempfile = Tempfile.new(["render",".pdf"],:encoding => 'ascii-8bit') begin pdf = Prawn::Document.new(skip_page_creation: true, margin: 0) render_into(pdf) tempfile.write pdf.render tempfile.rewind yield tempfile ensure tempfile.unlink end end
render_into(pdf)
click to toggle source
# File lib/pdf_tempura/renderer.rb, line 14 def render_into(pdf) @pages.to_enum.with_index(0).each do |page, index| pdf.start_new_page template: @template_path, template_page: ((index % @template_page_count) + 1) Render::Page.new(page,@options).render(pdf) end end