Sha256: 2007bbd2976d60114076a7ded7871cdd33fec3e4cb34b46c8b5c091f9400d71d

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8
#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.dirname(__FILE__)+"/../lib/")


require 'rubygems'
require 'rtf'

include RTF

# Create required styles.
styles = {}
styles['HEADER'] = CharacterStyle.new
styles['HEADER'].bold      = true
styles['HEADER'].font_size = 28
styles['NORMAL'] = ParagraphStyle.new
styles['NORMAL'].justification = ParagraphStyle::FULL_JUSTIFY
styles['INDENTED'] = ParagraphStyle.new
styles['INDENTED'].left_indent = 400

document = Document.new(Font.new(Font::ROMAN, 'Arial'))
document.paragraph do |p|
   p.apply(styles['HEADER']) do |s|
      s << '1.0 Introduction'
   end
end
document.paragraph(styles['NORMAL']) do |p|
   p << 'Here is a short example program in the Ruby programming '
   p << 'language that demonstrates writing a single line of text '
   p << 'to a file created in the current working directory...'
end

c = 1
document.paragraph(styles['INDENTED']) do |n1|
   n1.line_break
   n1.font(Font.new(Font::MODERN, 'Courier New')) do |n2|
      n2 << "#{sprintf('%02d', c)}   File.open('output.txt', 'w') do |file|"
      c += 1
      n2.line_break
      n2 << "#{sprintf('%02d', c)}      file.write('Some text.')"
      c += 1
      n2.line_break
      n2 << "#{sprintf('%02d', c)}   end"
   end
end

document.line_break
document.paragraph(styles['NORMAL']) do |p|
   p << "And there you have it. A simple example indeed."
end

File.open('example01.rtf', 'w') do |file|
   file.write(document.to_rtf)
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
clbustos-rtf-0.5.0 examples/example01.rb
rtf-0.3.3 examples/example01.rb
rtf-0.3.2 examples/example01.rb