Simple % Bar In A Pdf Using Ruby
Join the DZone community and get the full member experience.
Join For FreeWill 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
Opinions expressed by DZone contributors are their own.
Comments