You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_unicode.rfpdf 4.8 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <%
  2. doc_title = "test title";
  3. doc_subject = "test description";
  4. doc_keywords = "test keywords";
  5. htmlcontent = "&lt; € &euro; &#8364; &amp; è &egrave; &copy; &gt;<br /><h1>heading 1</h1><h3>heading 2</h3><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, 'public')}/logo_example.png\" alt=\"test alt attribute\" width=\"100\" height=\"100\" border=\"0\" />";
  6. # ENGLISH
  7. @l = {}
  8. # PAGE META DESCRIPTORS --------------------------------------
  9. @l['a_meta_charset'] = "UTF-8";
  10. @l['a_meta_dir'] = "ltr";
  11. @l['a_meta_language'] = "en";
  12. # TRANSLATIONS --------------------------------------
  13. @l['w_page'] = "page";
  14. # create new PDF document (document units are set by default to millimeters)
  15. pdf = TCPDF.new
  16. # set document information
  17. pdf.SetCreator("TCPDF");
  18. pdf.SetAuthor("TCPDF");
  19. pdf.SetTitle(doc_title);
  20. pdf.SetSubject(doc_subject);
  21. pdf.SetKeywords(doc_keywords);
  22. pdf.SetHeaderData("#{File.join(RAILS_ROOT, 'public')}/logo_example.png", 20, "header title", "first row\nsecond row\nthird row");
  23. #set margins
  24. pdf.SetMargins(15, 27, 15);
  25. #set auto page breaks
  26. pdf.SetAutoPageBreak(true, 25);
  27. pdf.SetPrintHeader
  28. pdf.SetPrintFooter
  29. pdf.SetHeaderMargin(5);
  30. pdf.SetFooterMargin(10);
  31. pdf.SetImageScale(4); #set image scale factor
  32. pdf.SetHeaderFont(["FreeSans", '', 10]);
  33. pdf.SetFooterFont(["FreeSans", '', 8]);
  34. pdf.SetLanguageArray(@l); #set language items
  35. #initialize document
  36. pdf.alias_nb_pages();
  37. pdf.AddPage();
  38. # set barcode
  39. # pdf.SetBarcode(Time.now.strftime("Y-m-d H:i:s"));
  40. # output some HTML code
  41. pdf.SetFont("vera", "", 10);
  42. pdf.writeHTML(htmlcontent, true, 0);
  43. # output two html columns
  44. first_column_width = 80;
  45. current_y_position = pdf.GetY();
  46. pdf.writeHTMLCell(first_column_width, 0, 0, current_y_position, "<b>hello</b>", 0, 0, 0);
  47. pdf.writeHTMLCell(0, 0, first_column_width, current_y_position, "<i>world</i>", 0, 1, 0);
  48. # output some content
  49. pdf.SetFont("vera", "BI", 20);
  50. pdf.Cell(0,10,"TEST Bold-Italic Cell",1,1,'C');
  51. # output some UTF-8 test content
  52. pdf.AddPage();
  53. pdf.SetFont("FreeSans", "", 12);
  54. utf8text = open(File.join(RAILS_ROOT, 'vendor/plugins/rfpdf',"utf8test.txt"), "rb").read; # get utf-8 text form file
  55. pdf.SetFillColor(230, 240, 255, true);
  56. pdf.Write(5, utf8text, '', 1);
  57. # remove page header/footer
  58. pdf.SetPrintHeader(false);
  59. pdf.SetPrintFooter(false);
  60. # Two HTML columns test
  61. pdf.AddPage();
  62. right_column = "<b>right column</b> right column right column right column right column
  63. right column right column right column right column right column right column
  64. right column right column right column right column right column right column";
  65. left_column = "<b>left column</b> left column left column left column left column left
  66. column left column left column left column left column left column left column
  67. left column left column left column left column left column left column left
  68. column";
  69. first_column_width = 80;
  70. second_column_width = 80;
  71. column_space = 20;
  72. current_y_position = pdf.GetY();
  73. pdf.writeHTMLCell(first_column_width, 0, 0, 0, left_column, 1, 0, 0);
  74. pdf.Cell(0);
  75. pdf.writeHTMLCell(second_column_width, 0, first_column_width+column_space, current_y_position, right_column, 0, 0, 0);
  76. # add page header/footer
  77. pdf.SetPrintHeader(true);
  78. pdf.SetPrintFooter(true);
  79. pdf.AddPage();
  80. # Multicell test
  81. pdf.MultiCell(40, 5, "A test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0);
  82. pdf.MultiCell(40, 5, "B test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0);
  83. pdf.MultiCell(40, 5, "C test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0);
  84. pdf.MultiCell(40, 5, "D test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 2);
  85. pdf.MultiCell(40, 5, "F test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0);
  86. #Close and output PDF document
  87. %><%=pdf.Output()%>

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...