Search code examples
rubyrtfbulletedlist

How to add bullet point in rtf file in ruby


This is working code to add the paragraph in rtf file.

document = Document.new(Font.new(Font::ROMAN, 'Times new Roman'))

@drugs.each do |drug|
  document.paragraph(styles['NORMAL']) do |p|
    p << "#{drug.name}"       
  end
end

Current display format is listed below:

drug one

drug two 

drug three

However,required display format is:

  • first drug

  • second drug

  • third drug


Solution

  • Your code is using the 'rtf' ruby gem, so my following answer is based on this.

    There may be other libraries available to solve this problem, or you could even consider writing your own solution, based on the RTF specification.

    Unfortunately, the README of both the original project and the official "bug fix" fork do not mention how to format bullet points with the library. (Also, neither projects have been updated in about 5 years...) The github code was originally copied from this ruby-forge project, which also does not mention bullet points.

    In times like this, you unfortunately need to dig in to the actual source code to find out what's supported by the library - and sure enough, you'll find RTF::ListTable which seems to handle bullet points.

    However, you will not find this in your version of the library. This github version of the gem appears to be uploaded as a different ruby gem. To use this updated version of the library, you will need the clbustos-rtf gem instead.