To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / lib / plugins / rfpdf / test_unicode.rfpdf @ 1298:4f746d8966dd

History | View | Annotate | Download (4.7 KB)

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><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, 'public')}/logo_example.png\" alt=\"test alt attribute\" width=\"100\" height=\"100\" border=\"0\" />";
6

    
7

    
8
  # ENGLISH
9

    
10
  @l = {}
11

    
12
  # PAGE META DESCRIPTORS --------------------------------------
13

    
14
  @l['a_meta_charset'] = "UTF-8";
15
  @l['a_meta_dir'] = "ltr";
16
  @l['a_meta_language'] = "en";
17

    
18
  # TRANSLATIONS --------------------------------------
19
  @l['w_page'] = "page";
20

    
21

    
22
  # create new PDF document (document units are set by default to millimeters)
23
  pdf = TCPDF.new
24

    
25
  # set document information
26
  pdf.SetCreator("TCPDF");
27
  pdf.SetAuthor("TCPDF");
28
  pdf.SetTitle(doc_title);
29
  pdf.SetSubject(doc_subject);
30
  pdf.SetKeywords(doc_keywords);
31

    
32
  pdf.SetHeaderData("#{File.join(RAILS_ROOT, 'public')}/logo_example.png", 20, "header title", "first row\nsecond row\nthird row");
33

    
34
  #set margins
35
  pdf.SetMargins(15, 27, 15);
36
  #set auto page breaks
37
  pdf.SetAutoPageBreak(true, 25);
38
  pdf.SetPrintHeader
39
  pdf.SetPrintFooter
40
  pdf.SetHeaderMargin(5);
41
  pdf.SetFooterMargin(10);
42
  pdf.SetImageScale(4); #set image scale factor
43

    
44
  pdf.SetHeaderFont(["FreeSans", '', 10]);
45
  pdf.SetFooterFont(["FreeSans", '', 8]);
46

    
47
  pdf.SetLanguageArray(@l); #set language items
48

    
49

    
50
  #initialize document
51
  pdf.alias_nb_pages();
52

    
53
  pdf.AddPage();
54

    
55
  # set barcode
56
  # pdf.SetBarcode(Time.now.strftime("Y-m-d H:i:s"));
57

    
58
  # output some HTML code
59
  pdf.SetFont("vera", "", 10);
60
    
61
  pdf.writeHTML(htmlcontent, true, 0);
62

    
63
  # output two html columns
64
  first_column_width = 80;
65
  current_y_position = pdf.GetY();
66
  pdf.writeHTMLCell(first_column_width, 0, 0, current_y_position, "<b>hello</b>", 0, 0, 0); 
67
  pdf.writeHTMLCell(0, 0, first_column_width, current_y_position, "<i>world</i>", 0, 1, 0); 
68
 
69
  # output some content
70
  pdf.SetFont("vera", "BI", 20);
71
  pdf.Cell(0,10,"TEST Bold-Italic Cell",1,1,'C');
72
 
73
  # output some UTF-8 test content
74
  pdf.AddPage();
75
  pdf.SetFont("FreeSans", "", 12);
76
  utf8text = open(File.join(RAILS_ROOT, 'vendor/plugins/rfpdf',"utf8test.txt"), "rb").read; # get utf-8 text form file
77
  pdf.SetFillColor(230, 240, 255, true);
78
  pdf.Write(5, utf8text, '', 1);
79
  
80
  # remove page header/footer
81
  pdf.SetPrintHeader(false);
82
  pdf.SetPrintFooter(false);
83
  
84
  # Two HTML columns test
85
  pdf.AddPage();
86
  right_column = "<b>right column</b> right column right column right column right column
87
  right column right column right column right column right column right column
88
  right column right column right column right column right column right column";
89
  left_column = "<b>left column</b> left column left column left column left column left
90
  column left column left column left column left column left column left column
91
  left column left column left column left column left column left column left
92
  column";
93
  first_column_width = 80;
94
  second_column_width = 80;
95
  column_space = 20; 
96
  current_y_position = pdf.GetY(); 
97
  pdf.writeHTMLCell(first_column_width, 0, 0, 0, left_column, 1, 0, 0);
98
  pdf.Cell(0);
99
  pdf.writeHTMLCell(second_column_width, 0, first_column_width+column_space, current_y_position, right_column, 0, 0, 0);
100
  
101
  # add page header/footer
102
  pdf.SetPrintHeader(true);
103
  pdf.SetPrintFooter(true);
104
  
105
  pdf.AddPage();
106

    
107
  # Multicell test
108
  pdf.MultiCell(40, 5, "A test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0);
109
  pdf.MultiCell(40, 5, "B test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0);
110
  pdf.MultiCell(40, 5, "C test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0);
111
  pdf.MultiCell(40, 5, "D test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 2);
112
  pdf.MultiCell(40, 5, "F test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0);
113

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