Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Simple % bar in a pdf using Ruby

Will create a bar, filled to the percentage provided, and draw it in a PDF.

Requires PDF Writer, call method after setting up PDF to @pdf

  def generate_pdf_bar(p = 50, x = 10, y = 'center', w = 200, h = 10)
     # adjustments
    if y == 'center'
      y = @pdf.page_height / 2 - h
    else
      y = @pdf.page_height - y - h
    end
    p = w / 100 * p

      # Empty
    @pdf.stroke_color  Color::RGB::Black
    @pdf.rectangle(x, y, w, h).close_stroke

     # Fill
    @pdf.fill_color    Color::RGB::Black
    @pdf.stroke_color  Color::RGB::Black
    @pdf.rectangle(x, y, p, h).close_fill_stroke
  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS