Chris@0: = RFPDF Template Plugin Chris@0: Chris@0: A template plugin allowing the inclusion of ERB-enabled RFPDF template files. Chris@0: Chris@0: == Example .rb method Usage Chris@0: Chris@0: In the controller, something like: Chris@0: Chris@0: def mypdf Chris@0: pdf = FPDF.new() Chris@0: Chris@0: # Chris@0: # Chinese Chris@0: # Chris@0: pdf.extend(PDF_Chinese) Chris@0: pdf.AddPage Chris@0: pdf.AddBig5Font Chris@0: pdf.SetFont('Big5','',18) Chris@0: pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %') Chris@0: icBig5 = Iconv.new('Big5', 'UTF-8') Chris@0: pdf.Write(15, icBig5.iconv("宋体 should be working")) Chris@0: send_data pdf.Output, :filename => "something.pdf", :type => "application/pdf" Chris@0: end Chris@0: Chris@0: == Example .rfdf Usage Chris@0: Chris@0: In the controller, something like: Chris@0: Chris@0: def mypdf Chris@0: @options_for_rfpdf ||= {} Chris@0: @options_for_rfpdf[:file_name] = "nice_looking.pdf" Chris@0: end Chris@0: Chris@0: In the layout (make sure this is the only item in the layout): Chris@0: <%= @content_for_layout %> Chris@0: Chris@0: In the view (mypdf.rfpdf): Chris@0: Chris@0: <% Chris@0: pdf = FPDF.new() Chris@0: # Chris@0: # Chinese Chris@0: # Chris@0: pdf.extend(PDF_Chinese) Chris@0: pdf.AddPage Chris@0: pdf.AddBig5Font Chris@0: pdf.SetFont('Big5','',18) Chris@0: pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %') Chris@0: icBig5 = Iconv.new('Big5', 'UTF-8') Chris@0: pdf.Write(15, icBig5.iconv("宋体 should be working")) Chris@0: Chris@0: # Chris@0: # Japanese Chris@0: # Chris@0: pdf.extend(PDF_Japanese) Chris@0: pdf.AddSJISFont(); Chris@0: pdf.AddPage(); Chris@0: pdf.SetFont('SJIS','',18); Chris@0: pdf.Write(5,'9ÉñåéÇÃåˆäJÉeÉXÉgÇåoǃPHP 3.0ÇÕ1998îN6åéÇ…åˆéÆÇ…ÉäÉäÅ[ÉXÇ≥ÇÍNjǵÇΩÅB'); Chris@0: icSJIS = Iconv.new('SJIS', 'UTF-8') Chris@0: pdf.Write(15, icSJIS.iconv("これはテキストである should be working")) Chris@0: Chris@0: # Chris@0: # Korean Chris@0: # Chris@0: pdf.extend(PDF_Korean) Chris@0: pdf.AddUHCFont(); Chris@0: pdf.AddPage(); Chris@0: pdf.SetFont('UHC','',18); Chris@0: pdf.Write(5,'PHP 3.0Àº 1998³â 6¿ù¿¡ °ø½ÄÀûÀ¸·Î ¸±¸®ÁîµÇ¾ú´Ù. °ø°³ÀûÀÎ Å×½ºÆ® ÀÌÈľà 9°³¿ù¸¸À̾ú´Ù.'); Chris@0: icUHC = Iconv.new('UHC', 'UTF-8') Chris@0: pdf.Write(15, icUHC.iconv("이것은 원본 이다")) Chris@0: Chris@0: # Chris@0: # English Chris@0: # Chris@0: pdf.AddPage(); Chris@0: pdf.SetFont('Arial', '', 10) Chris@0: pdf.Write(5, "should be working") Chris@0: %> Chris@0: <%= pdf.Output() %> Chris@0: Chris@0: Chris@0: == Configuring Chris@0: Chris@0: You can configure Rfpdf by using an @options_for_rfpdf hash in your controllers. Chris@0: Chris@0: Here are a few options: Chris@0: Chris@0: :filename (default: action_name.pdf) Chris@0: Filename of PDF to generate Chris@0: Chris@0: Note: If you're using the same settings for @options_for_rfpdf often, you might want to Chris@0: put your assignment in a before_filter (perhaps overriding :filename, etc in your actions). Chris@0: Chris@0: == Problems Chris@0: Chris@0: Layouts and partials are currently not supported; just need Chris@0: to wrap the PDF generation differently.