Skip to content

Instantly share code, notes, and snippets.

@sabril
Created December 15, 2010 01:01
Show Gist options
  • Save sabril/741445 to your computer and use it in GitHub Desktop.
Save sabril/741445 to your computer and use it in GitHub Desktop.
this is for print job
format.pdf {
table_of_content_pages = Hash.new
for specification in @job.specifications
specification_sections = SpecificationSection.specification_id_eq(specification.id)
for specification_section in specification_sections
pdf = Prawn::Document.new(:page_size => "LETTER", :top_margin => 0.5.in, :left_margin => 1.3.in, :bottom_margin => 0.in, :right_margin => 0.8.in )
if report_article_number(specification_section.specification.division.short_number) != "00"
pdf.bounding_box([0, 700], :width => 460, :height => 610 ) do
pdf.text "SECTION #{specification_section.section.report_print_number}", :align => :center, :size => 9, :style => :bold
pdf.move_down(5)
pdf.text "#{specification_section.section.name.upcase}", :align => :center, :size => 9, :style => :bold
for part in @parts
pdf.move_down(10)
articles = PartArticle.part_id_eq(part.id).specification_section_id_eq(specification_section.id).all(:order => "articles.id ASC", :include => [:article, :specification_section, {:article_paragraphs => [:subparagraphs, :paragraph]}, :user_paragraphs])
is_present = true
if articles.blank?
is_present = false
end
unless is_present
pdf.table([["PART #{part.id} #{part.name.upcase} - NOT USED"]], :cell_style => {:size => 9, :font_style => :bold}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 380 }
end
else
pdf.table([["PART #{part.id} - #{part.name.upcase}"]], :cell_style => {:size => 9, :font_style => :bold}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 380 }
end
end
a = 1
for article in articles
if @job.show_notes
unless article.note.blank?
pdf.fill_color "309030"
pdf.table([["#{article.note}"]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 440 }
end
pdf.fill_color "000000"
end
end
pdf.table([["#{part.id}.#{report_article_number(a)}", article.article.name.upcase]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 380 }
end
b = 97
for paragraph in article.article_paragraphs
if @job.show_notes
unless paragraph.note.blank?
pdf.fill_color "309030"
pdf.table([["","#{paragraph.note}"]], :cell_style => {:size => 9, :padding => 4}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 420 }
end
end
pdf.fill_color "000000"
end
pdf.table([["","#{b.chr.upcase}.",paragraph.paragraph.name]], :cell_style => {:size => 9, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 20 }
t.style(t.columns(2)) { |cell| cell.width = 380 }
end
c = 1
for subparagraph in paragraph.subparagraphs
if @job.show_notes
unless subparagraph.note.blank?
pdf.fill_color "309030"
pdf.table([["","#{subparagraph.note}"]], :cell_style => {:size => 9, :padding => 4}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 55 }
t.style(t.columns(1)) { |cell| cell.width = 400 }
end
end
pdf.fill_color "000000"
end
pdf.table([["","#{c}.",convert_html(subparagraph.description)]], :cell_style => {:size => 9, :inline_format => true, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 55 }
t.style(t.columns(1)) { |cell| cell.width = 25 }
t.style(t.columns(2)) { |cell| cell.width = 380 }
end
c += 1
end
b += 1
end
a += 1
end
end
attachments = SectionAttachment.specification_section_id_eq(specification_section.id)
if attachments.size > 0
pdf.move_down(10)
pdf.text "ATTACHMENTS", :align => :center, :size => 9, :style => :bold
ind = 1
end
for attachment in attachments
pdf.table([["#{ind}.","#{attachment.title}"]], :cell_style => {:size => 9, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 30 }
t.style(t.columns(1)) { |cell| cell.width = 380 }
end
ind = ind + 1
end
pdf.move_down(10)
pdf.text "END OF SECTION", :align => :center, :size => 9, :style => :bold
table_of_content_pages[specification_section.id] = pdf.page_count
end # end of bounding box
pdf.page_count.times do |i|
pdf.go_to_page(i+1)
pdf.bounding_box([pdf.bounds.right - 245, pdf.bounds.bottom + 70], :width =>250, :align => :right) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left, pdf.bounds.bottom + 70], :width => 250, :align => :left) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_left_3, pdf)}", :size => 9, :align => :left
}
pdf.bounding_box([pdf.bounds.right - 240, pdf.bounds.top], :width =>250, :align => :right) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left + 3, pdf.bounds.top], :width =>250, :align => :left) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_left_3, pdf)}", :size => 9, :align => :left
}
if current_user.billing_plan.plan_type_id == 1
pdf.bounding_box([pdf.bounds.left + 185, pdf.bounds.bottom + 70], :width => 300, :align => :left) {
pdf.text "www.myspecwriter.com", :size => 9, :align => :left
}
end
end
else
pdf.bounding_box([0, 700], :width => 460, :height => 610 ) do
pdf.table([["#{specification_section.section.report_print_number} #{specification_section.section.name.upcase}"]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 380 }
end
pdf.move_down(10)
@articles = UserArticle.find_all_by_specification_section_id(specification_section.id)
unless @articles.blank?
pdf.text "Table of Articles", :align => :center, :size => 9, :style => :bold
a = 1
for article in @articles
pdf.table([["#{a}.01",article.name]], :cell_style => {:size => 9, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 380 }
end
a = a + 1
end
end
attachments = SectionAttachment.specification_section_id_eq(specification_section.id)
if attachments.size > 0
pdf.move_down(10)
pdf.text "Attachments", :align => :center, :size => 9, :style => :bold
ind = 1
end
for attachment in attachments
pdf.table([["#{ind}.","#{attachment.title}"]], :cell_style => {:size => 9, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 25 }
t.style(t.columns(1)) { |cell| cell.width = 380 }
end
ind = ind + 1
end
pdf.move_down(20)
unless @articles.blank?
a = 1
for article in @articles
if @job.show_notes
unless article.note.blank?
pdf.fill_color "309030"
pdf.table([["#{article.note}"]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 440 }
end
pdf.fill_color "000000"
end
end
pdf.table([["#{a}.01",article.name]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 420 }
end
a += 1
b = 97
c = 1
for paragraph in article.user_paragraphs
if @job.show_notes
unless paragraph.note.blank?
pdf.fill_color "309030"
pdf.table([["","#{paragraph.note}"]], :cell_style => {:size => 9, :padding => 4}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 10 }
t.style(t.columns(1)) { |cell| cell.width = 420 }
end
end
pdf.fill_color "000000"
end
pdf.table([["", "#{b.chr.upcase}.", convert_html(paragraph.paragraph)]], :cell_style => {:size => 9, :inline_format => true, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 10 }
t.style(t.columns(1)) { |cell| cell.width = 25 }
t.style(t.columns(2)) { |cell| cell.width = 420 }
end
for subparagraph in paragraph.user_subparagraphs
if @job.show_notes
unless subparagraph.note.blank?
pdf.fill_color "309030"
pdf.table([["","#{subparagraph.note}"]], :cell_style => {:size => 9, :padding => 4}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 400 }
end
end
pdf.fill_color "000000"
end
pdf.table([["","#{c}.",convert_html(subparagraph.description)]], :cell_style => {:size => 9, :inline_format => true, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 35 }
t.style(t.columns(1)) { |cell| cell.width = 25 }
t.style(t.columns(2)) { |cell| cell.width = 400 }
end
c += 1
end
b += 1
end
end
end
end
table_of_content_pages[specification_section.id] = pdf.page_count
pdf.page_count.times do |i|
pdf.go_to_page(i+1)
pdf.bounding_box([pdf.bounds.right - 245, pdf.bounds.bottom + 70], :width =>250, :align => :right) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left, pdf.bounds.bottom + 70], :width => 250, :align => :left) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.bottom_left_3, pdf)}", :size => 9, :align => :left
}
pdf.bounding_box([pdf.bounds.right - 240, pdf.bounds.top], :width =>250, :align => :right) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left + 3, pdf.bounds.top], :width =>250, :align => :left) {
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{specification_section.choose_option(@job.job_page_format.top_left_3, pdf)}", :size => 9, :align => :left
}
end
if current_user.billing_plan.plan_type_id == 1
pdf.bounding_box([pdf.bounds.left + 185, pdf.bounds.bottom + 70], :width => 300, :align => :left) {
pdf.text "www.myspecwriter.com", :size => 9, :align => :left
}
end
end
File.open(dir + "/"+ specification_section.section.number+ ".pdf", "w") { |f| f.write pdf.render }
pdf = nil
end
end
pdf = Prawn::Document.new(:page_size => "LETTER", :top_margin => 0.5.in, :left_margin => 1.3.in, :bottom_margin => 0.in, :right_margin => 0.8.in )
pdf.font "Helvetica"
pdf.bounding_box([0, 700], :width => 460, :height => 610 ) do
pdf.text "TABLE OF CONTENTS", :align => :center, :size => 9, :style => :bold
pdf.move_down(10)
for specification in @job.specifications
#pdf.text "DIVISION #{specification.division.search_number} - #{specification.division.name}".upcase, :style => :bold, :size => 9
pdf.move_down(10)
pdf.table([[specification.division.modif_number, specification.division.name]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 65 }
t.style(t.columns(1)) { |cell| cell.width = 340 }
end
if(!specification.specification_sections.blank?)
specification.specification_sections.each do |item|
pdf.table([["","#{item.section.modif_number}",item.section.name,table_of_content_pages[item.id].to_s]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 65 }
t.style(t.columns(1)) { |cell| cell.width = 65 }
t.style(t.columns(2)) { |cell| cell.width = 300 }
t.style(t.columns(3)) { |cell| cell.width = 25 }
end
attachments = SectionAttachment.specification_section_id_eq(item.id)
if attachments.size > 0
ind = 1
for attachment in attachments
pdf.table([["","#{ind}","", "#{attachment.title}"]], :cell_style => {:size => 9, :padding => 3}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 65 }
t.style(t.columns(1)) { |cell| cell.width = 45 }
t.style(t.columns(2)) { |cell| cell.width = 20 }
t.style(t.columns(3)) { |cell| cell.width = 340 }
end
ind = ind + 1
end
end
end
end
end
pdf.move_down(15)
pdf.text "END OF SECTION", :align => :center, :size => 9, :style => :bold
end
pdf.page_count.times do |i|
pdf.go_to_page(i+1)
pdf.bounding_box([pdf.bounds.right - 245, pdf.bounds.bottom + 70], :width =>250, :align => :right) {
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left, pdf.bounds.bottom + 70], :width => 250, :align => :left) {
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_left_3, pdf)}", :size => 9, :align => :left
}
pdf.bounding_box([pdf.bounds.right - 240, pdf.bounds.top], :width =>250, :align => :right) {
pdf.text "#{@job.choose_option(@job.job_page_format.top_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.top_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.top_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left + 3, pdf.bounds.top], :width =>250, :align => :left) {
pdf.text "#{@job.choose_option(@job.job_page_format.top_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.top_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.top_left_3, pdf)}", :size => 9, :align => :left
}
if current_user.billing_plan.plan_type_id == 1
pdf.bounding_box([pdf.bounds.left + 185, pdf.bounds.bottom + 70], :width => 300, :align => :left) {
pdf.text "www.myspecwriter.com", :size => 9, :align => :left
}
end
end
#SECTION FOR NOTE CREATION
pdf = Prawn::Document.new(:page_size => "LETTER", :top_margin => 0.5.in, :left_margin => 1.3.in, :bottom_margin => 0.in, :right_margin => 0.8.in )
pdf.font "Helvetica"
pdf.bounding_box([0, 700], :width => 460, :height => 610 ) do
pdf.text "NOTES", :align => :center, :size => 9, :style => :bold
for specification in @job.specifications
pdf.move_down(10)
pdf.table([[specification.division.modif_number, specification.division.name]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 50 }
t.style(t.columns(1)) { |cell| cell.width = 340 }
end
if(!specification.specification_sections.blank?)
specification.specification_sections.each do |item|
notes = SectionNote.specification_section_id_eq(item.id)
@attachments = SectionAttachment.specification_section_id_eq(item.id)
#get all attachments
if !@attachments.blank?
@ccf = CloudFiles::Connection.new(CLOUD_CONFIG['username'],CLOUD_CONFIG['api_key'])
container = @ccf.container(as_container)
i = 1
for attachment in @attachments
if container.object_exists?(attachment.asset.path)
object = container.object(attachment.asset.path)
tmp = File.open(dir + "/"+attachment.specification_section.section.number.to_s+""+i.to_s+".pdf", "w+")
tmp.syswrite(object.data)
i += 1
end
end
end
if notes.size > 0
pdf.table([["","#{item.section.modif_number}", "#{item.section.name}"]], :cell_style => {:size => 9}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 50 }
t.style(t.columns(1)) { |cell| cell.width = 65 }
t.style(t.columns(2)) { |cell| cell.width = 320 }
end
ind = 1
for note in notes
pdf.table([["","","#{ind}.", "#{convert_html(note.note)}"]], :cell_style => {:size => 9, :inline_format => true}) do |t|
t.cells.borders = []
t.style(t.columns(0)) { |cell| cell.width = 50 }
t.style(t.columns(1)) { |cell| cell.width = 65 }
t.style(t.columns(2)) { |cell| cell.width = 25 }
t.style(t.columns(3)) { |cell| cell.width = 300 }
end
ind = ind + 1
end
end
end
end
end
pdf.move_down(15)
pdf.text "END OF SECTION", :align => :center, :size => 9, :style => :bold
end
pdf.page_count.times do |i|
pdf.go_to_page(i+1)
pdf.bounding_box([pdf.bounds.right - 245, pdf.bounds.bottom + 70], :width =>250, :align => :right) {
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left, pdf.bounds.bottom + 70], :width => 250, :align => :left) {
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.bottom_left_3, pdf)}", :size => 9, :align => :left
}
pdf.bounding_box([pdf.bounds.right - 240, pdf.bounds.top], :width =>250, :align => :right) {
pdf.text "#{@job.choose_option(@job.job_page_format.top_right_1, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.top_right_2, pdf)}", :size => 9, :align => :right
pdf.text "#{@job.choose_option(@job.job_page_format.top_right_3, pdf)}", :size => 9, :align => :right
}
pdf.bounding_box([pdf.bounds.left + 3, pdf.bounds.top], :width =>250, :align => :left) {
pdf.text "#{@job.choose_option(@job.job_page_format.top_left_1, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.top_left_2, pdf)}", :size => 9, :align => :left
pdf.text "#{@job.choose_option(@job.job_page_format.top_left_3, pdf)}", :size => 9, :align => :left
}
if current_user.billing_plan.plan_type_id == 1
pdf.bounding_box([pdf.bounds.left + 185, pdf.bounds.bottom + 70], :width => 300, :align => :left) {
pdf.text "www.myspecwriter.com", :size => 9, :align => :left
}
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment