Example PDF class for Prawn
class BriefPdf < Prawn::Document | |
def initialize(brief, user) | |
super(top_margin: 70, left_margin: 80, right_margin: 80, bottom_margin: 50) | |
@brief = brief | |
@user = user | |
header | |
company | |
contact | |
project | |
end | |
def header | |
left = bounds.left - 80 | |
right = bounds.right + 80 | |
full_width = bounds.width + 160 | |
stroke do | |
horizontal_line left, right, at: bounds.top + 51 | |
stroke_color "CCCCCC" | |
end | |
fill do | |
rectangle [left, bounds.top + 50], full_width, 60 | |
fill_color "EEEEEE" | |
end | |
stroke do | |
horizontal_line left, right, at: bounds.top - 10 | |
stroke_color "CCCCCC" | |
end | |
bounding_box [left, bounds.top + 35], | |
width: full_width, | |
height: 60 do | |
font "Helvetica" | |
fill_color "666666" | |
text "CS Workflow Copywriting Brief", align: :center, size: 20 | |
fill_color "333333" | |
text "Created for <b>#{@user.name}</b>", align: :center, size: 12, inline_format: :true | |
end | |
end | |
def contact | |
bounding_box [(bounds.width/2)+20, bounds.top-30], width: (bounds.width/2)-20 do | |
section_heading("Contact") | |
text @brief.name | |
text @brief.phone | |
text @brief.email | |
end | |
end | |
def company | |
bounding_box [bounds.left, bounds.top-30], width: (bounds.width/2)-20 do | |
section_heading("Company") | |
text @brief.company_name | |
text @brief.company_tagline | |
text "<color rgb='0000dd'>#{@brief.company_website}</color>", inline_format: true | |
end | |
end | |
def project | |
section_heading("Project") | |
move_down 5 | |
text @brief.title, size: 16, style: :bold | |
text "Deadline: #{@brief.deadline}", size: 14 | |
move_down 10 | |
section_item("Description", @brief.description) | |
section_item("Objective", @brief.objective) | |
section_item("Audience", @brief.audience) | |
section_item("Voice", @brief.voice) | |
section_item("Pitch", @brief.pitch) | |
section_item("Things to include", @brief.must_include) | |
section_item("Things to avoid", @brief.must_not_include) | |
section_item("Lead in", @brief.lead_in) | |
section_item("Available material", @brief.material.blank? ? "None" : @brief.material) | |
section_item("Inspiration", @brief.inspiration.blank? ? "None" : @brief.inspiration) | |
section_item("General comments", @brief.general_comments.blank? ? "None" : @brief.general_comments) | |
end | |
def section_heading(str) | |
move_down 20 | |
text str, size: 20, style: :bold | |
end | |
def section_item(head, body) | |
text head, size: 14, style: :bold | |
text body | |
move_down 15 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment