Skip to content

Instantly share code, notes, and snippets.

@mh-github
Last active March 17, 2017 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mh-github/8736c86d28745332842540f6e89b1471 to your computer and use it in GitHub Desktop.
Save mh-github/8736c86d28745332842540f6e89b1471 to your computer and use it in GitHub Desktop.
require 'prawn'
require 'prawn/table'
def bullet_item string
indent 15, 0 do
text "* " + string, :align => :justify
end
end
def bullet_item_2 string
if string.length > 110
sub_str = string[85..string.length-1]
space_index = sub_str.index(' ')
str1 = string[0..85+space_index]
str2 = string[86+space_index..string.length-1]
indent 10, 0 do
text "* " + str1, :align => :justify
indent(9) {text str2, :align => :justify}
end
else
indent 10, 0 do
text "* " + string, :align => :justify
end
end
end
def extractFirstPart(str)
return str if str.length < 110
substr = str[85..str.length-1]
space_index = substr.index(' ')
if space_index != nil
return str[0..85+space_index]
else
return str
end
end
def bullet_item_3 string
counter = 1
myStr = string.clone
while myStr.length > 0 do
str = extractFirstPart myStr
if counter == 1
indent 10, 0 do
text "* " + str, :align => :justify
end
else
indent(19) {text str, :align => :justify}
end
myStr.slice! str
counter += 1
end
end
def bullet_text_with_borderless_table_old data
bullet_data = []
data.each {|d| bullet_data << ["*", d]}
table bullet_data, {:cell_style => { :borders => [], :align => :justify }, header: true}
end
def bullet_text_with_borderless_table data
bullet_data = []
data.each {|d| bullet_data << ["*", d]}
t = make_table bullet_data, {:cell_style => { :borders => [], :align => :justify, :padding => [0,10,0,0]}, header: true}
indent(20) {t.draw}
end
Prawn::Document.generate("prawn-bullet-points.pdf") do
2.times {|i| text " "}
text "The first solution..."
bullet_item "This is bullet list line #1 "
bullet_item "This is bullet list line #2 "
2.times {|i| text " "}
text "The first solution with longer lines..."
bullet_item "This is bullet list line #1 "
bullet_item "An ecommerce application for online shopping may have several microservices involving order collection, account access, inventory management and shipping."
2.times {|i| text " "}
text "The second solution..."
bullet_item_2 "This is bullet list line #1 "
bullet_item_2 "An ecommerce application for online shopping may have several microservices involving order collection, account access, inventory management and shipping."
# https://en.wikipedia.org/wiki/Welding_Procedure_Specification
welding_procedure_specification = [
"A Welding Procedure Specification (WPS) is the formal written document describing welding procedures, which provides direction to the welder or welding operators for making sound and quality production welds as per the code requirements.",
"The purpose of the document is to guide welders to the accepted procedures so that repeatable and trusted welding techniques are used.",
"A WPS is developed for each material alloy and for each welding type used.",
"Specific codes and/or engineering societies are often the driving force behind the development of a company's WPS.",
"A WPS is supported by a Procedure Qualification Record (PQR or WPQR). A PQR is a record of a test weld performed and tested (more rigorously) to ensure that the procedure will produce a good weld.",
"Individual welders are certified with a qualification test documented in a Welder Qualification Test Record (WQTR) that shows they have the understanding and demonstrated ability to work within the specified WPS."
]
2.times {|i| text " "}
text "The third solution..."
welding_procedure_specification.each { |sentence| bullet_item_3 sentence }
2.times {|i| text " "}
text "The final solution..."
bullet_text_with_borderless_table welding_procedure_specification
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment