<%
  # Copyright (c) 2011-2017 NAITOH Jun
  # Released under the MIT license
  # http://www.opensource.org/licenses/MIT

  doc_title = "test title"
  doc_subject = "test description"
  doc_keywords = "test keywords"
  htmlcontent = "&lt; € &euro; &#8364; &amp; è &egrave; &copy; &gt;<br /><h1>heading 1</h1><h2>heading 2</h2><h3>heading 3</h3><h4>heading 4</h4><h5>heading 5</h5><h6>heading 6</h6>ordered list:<br /><ol><li><b>bold text</b></li><li><i>italic text</i></li><li><u>underlined text</u></li><li><a href=\"http:#www.tecnick.com\">link to http://www.tecnick.com</a></li><li>test break<br />second line<br />third line</li><li><font size=\"+3\">font + 3</font></li><li><small>small text</small></li><li>normal <sub>subscript</sub> <sup>superscript</sup></li></ul><hr />table:<br /><table border=\"1\" cellspacing=\"1\" cellpadding=\"1\"><tr><th>#</th><th>A</th><th>B</th></tr><tr><th>1</th><td bgcolor=\"#cccccc\">A1</td><td>B1</td></tr><tr><th>2</th><td>A2 € &euro; &#8364; &amp; è &egrave; </td><td>B2</td></tr><tr><th>3</th><td>A3</td><td><font color=\"#FF0000\">B3</font></td></tr></table><hr />image:<br /><img src=\"#{File.join(Rails.root.to_s, 'public')}/logo_example.png\" alt=\"test alt attribute\" width=\"100\" height=\"100\" border=\"0\" />"


  # ENGLISH

  @l = {}

  # PAGE META DESCRIPTORS --------------------------------------

  @l['a_meta_charset'] = "UTF-8"
  @l['a_meta_dir'] = "ltr"
  @l['a_meta_language'] = "en"

  # TRANSLATIONS --------------------------------------
  @l['w_page'] = "page"


  # create new PDF document (document units are set by default to millimeters)
  pdf = RBPDF.new

  # set document information
  pdf.set_creator("RBPDF")
  pdf.set_author("RBPDF")
  pdf.set_title(doc_title)
  pdf.set_subject(doc_subject)
  pdf.set_keywords(doc_keywords)

  pdf.set_header_data("#{File.join(Rails.root.to_s, 'public')}/logo_example.png", 20, "header title", "first row\nsecond row\nthird row")

  #set margins
  pdf.set_margins(15, 27, 15)
  #set auto page breaks
  pdf.set_auto_page_break(true, 25)
  pdf.set_print_header
  pdf.set_print_footer
  pdf.set_header_margin(5)
  pdf.set_footer_margin(10)
  pdf.set_image_scale(4); #set image scale factor

  pdf.set_header_font(["FreeSans", '', 10])
  pdf.set_footer_font(["FreeSans", '', 8])

  pdf.set_language_array(@l) # set language items


  #initialize document
  pdf.alias_nb_pages()

  pdf.add_page()

  # set barcode
  # pdf.set_barcode(Time.now.strftime("Y-m-d H:i:s"))

  # output some HTML code
  pdf.set_font("times", "", 10)
    
  pdf.write_html(htmlcontent, true, 0)

  # output two html columns
  first_column_width = 80
  current_y_position = pdf.get_y()
  pdf.write_html_cell(first_column_width, 0, '', current_y_position, "<b>hello</b>", 0, 0, 0) 
  pdf.write_html_cell(0, 0, first_column_width, current_y_position, "<i>world</i>", 0, 1, 0)
 
  # output some content
  pdf.set_font("times", "BI", 20)
  pdf.cell(0,10,"TEST Bold-Italic Cell",1,1,'C')
 
  # output some UTF-8 test content
  pdf.add_page()
  pdf.set_font("FreeSerif", "", 12)
  utf8text = open(File.join(Rails.root.to_s, 'public',"utf8test.txt"), "rb").read # get utf-8 text form file
  pdf.set_fill_color(230, 240, 255, true)
  pdf.write(5, utf8text, '', 1)
  
  # remove page header/footer
  pdf.set_print_header(false)
  pdf.set_print_footer(false)
  
  # Two HTML columns test
  pdf.add_page()
  right_column = "<b>right column</b> right column right column right column right column
  right column right column right column right column right column right column
  right column right column right column right column right column right column"
  left_column = "<b>left column</b> left column left column left column left column left
  column left column left column left column left column left column left column
  left column left column left column left column left column left column left
  column"
  first_column_width = 80
  second_column_width = 80
  column_space = 20
  current_y_position = pdf.get_y() 
  pdf.write_html_cell(first_column_width, 0, '', '', left_column, 1, 0, 0)
  pdf.cell(0)
  pdf.write_html_cell(second_column_width, 0, first_column_width+column_space, current_y_position, right_column, 0, 0, 0)
  
  # add page header/footer
  pdf.set_print_header(true)
  pdf.set_print_footer(true)
  
  pdf.add_page()

  # multi_cell test
  pdf.multi_cell(40, 5, "A test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0)
  pdf.multi_cell(40, 5, "B test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0)
  pdf.multi_cell(40, 5, "C test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0)
  pdf.multi_cell(40, 5, "D test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 2)
  pdf.multi_cell(40, 5, "F test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0)

  #Close and output PDF document
%><%==pdf.output()%>
