Chris@0
|
1 = RFPDF Template Plugin
|
Chris@0
|
2
|
Chris@0
|
3 A template plugin allowing the inclusion of ERB-enabled RFPDF template files.
|
Chris@0
|
4
|
Chris@0
|
5 == Example .rb method Usage
|
Chris@0
|
6
|
Chris@0
|
7 In the controller, something like:
|
Chris@0
|
8
|
Chris@0
|
9 def mypdf
|
Chris@0
|
10 pdf = FPDF.new()
|
Chris@0
|
11
|
Chris@0
|
12 #
|
Chris@0
|
13 # Chinese
|
Chris@0
|
14 #
|
Chris@0
|
15 pdf.extend(PDF_Chinese)
|
Chris@0
|
16 pdf.AddPage
|
Chris@0
|
17 pdf.AddBig5Font
|
Chris@0
|
18 pdf.SetFont('Big5','',18)
|
Chris@0
|
19 pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %')
|
Chris@0
|
20 icBig5 = Iconv.new('Big5', 'UTF-8')
|
Chris@0
|
21 pdf.Write(15, icBig5.iconv("宋体 should be working"))
|
Chris@0
|
22 send_data pdf.Output, :filename => "something.pdf", :type => "application/pdf"
|
Chris@0
|
23 end
|
Chris@0
|
24
|
Chris@0
|
25 == Example .rfdf Usage
|
Chris@0
|
26
|
Chris@0
|
27 In the controller, something like:
|
Chris@0
|
28
|
Chris@0
|
29 def mypdf
|
Chris@0
|
30 @options_for_rfpdf ||= {}
|
Chris@0
|
31 @options_for_rfpdf[:file_name] = "nice_looking.pdf"
|
Chris@0
|
32 end
|
Chris@0
|
33
|
Chris@0
|
34 In the layout (make sure this is the only item in the layout):
|
Chris@0
|
35 <%= @content_for_layout %>
|
Chris@0
|
36
|
Chris@0
|
37 In the view (mypdf.rfpdf):
|
Chris@0
|
38
|
Chris@0
|
39 <%
|
Chris@0
|
40 pdf = FPDF.new()
|
Chris@0
|
41 #
|
Chris@0
|
42 # Chinese
|
Chris@0
|
43 #
|
Chris@0
|
44 pdf.extend(PDF_Chinese)
|
Chris@0
|
45 pdf.AddPage
|
Chris@0
|
46 pdf.AddBig5Font
|
Chris@0
|
47 pdf.SetFont('Big5','',18)
|
Chris@0
|
48 pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %')
|
Chris@0
|
49 icBig5 = Iconv.new('Big5', 'UTF-8')
|
Chris@0
|
50 pdf.Write(15, icBig5.iconv("宋体 should be working"))
|
Chris@0
|
51
|
Chris@0
|
52 #
|
Chris@0
|
53 # Japanese
|
Chris@0
|
54 #
|
Chris@0
|
55 pdf.extend(PDF_Japanese)
|
Chris@0
|
56 pdf.AddSJISFont();
|
Chris@0
|
57 pdf.AddPage();
|
Chris@0
|
58 pdf.SetFont('SJIS','',18);
|
Chris@0
|
59 pdf.Write(5,'9ÉñåéÇÃåˆäJÉeÉXÉgÇåoǃPHP 3.0ÇÕ1998îN6åéÇ…åˆéÆÇ…ÉäÉäÅ[ÉXÇ≥ÇÍNjǵÇΩÅB');
|
Chris@0
|
60 icSJIS = Iconv.new('SJIS', 'UTF-8')
|
Chris@0
|
61 pdf.Write(15, icSJIS.iconv("これはテキストである should be working"))
|
Chris@0
|
62
|
Chris@0
|
63 #
|
Chris@0
|
64 # Korean
|
Chris@0
|
65 #
|
Chris@0
|
66 pdf.extend(PDF_Korean)
|
Chris@0
|
67 pdf.AddUHCFont();
|
Chris@0
|
68 pdf.AddPage();
|
Chris@0
|
69 pdf.SetFont('UHC','',18);
|
Chris@0
|
70 pdf.Write(5,'PHP 3.0Àº 1998³â 6¿ù¿¡ °ø½ÄÀûÀ¸·Î ¸±¸®ÁîµÇ¾ú´Ù. °ø°³ÀûÀÎ Å×½ºÆ® ÀÌÈľà 9°³¿ù¸¸À̾ú´Ù.');
|
Chris@0
|
71 icUHC = Iconv.new('UHC', 'UTF-8')
|
Chris@0
|
72 pdf.Write(15, icUHC.iconv("이것은 원본 이다"))
|
Chris@0
|
73
|
Chris@0
|
74 #
|
Chris@0
|
75 # English
|
Chris@0
|
76 #
|
Chris@0
|
77 pdf.AddPage();
|
Chris@0
|
78 pdf.SetFont('Arial', '', 10)
|
Chris@0
|
79 pdf.Write(5, "should be working")
|
Chris@0
|
80 %>
|
Chris@0
|
81 <%= pdf.Output() %>
|
Chris@0
|
82
|
Chris@0
|
83
|
Chris@0
|
84 == Configuring
|
Chris@0
|
85
|
Chris@0
|
86 You can configure Rfpdf by using an @options_for_rfpdf hash in your controllers.
|
Chris@0
|
87
|
Chris@0
|
88 Here are a few options:
|
Chris@0
|
89
|
Chris@0
|
90 :filename (default: action_name.pdf)
|
Chris@0
|
91 Filename of PDF to generate
|
Chris@0
|
92
|
Chris@0
|
93 Note: If you're using the same settings for @options_for_rfpdf often, you might want to
|
Chris@0
|
94 put your assignment in a before_filter (perhaps overriding :filename, etc in your actions).
|
Chris@0
|
95
|
Chris@0
|
96 == Problems
|
Chris@0
|
97
|
Chris@0
|
98 Layouts and partials are currently not supported; just need
|
Chris@0
|
99 to wrap the PDF generation differently.
|