Ruby Ruportʵ¼ù—ÖÐÎÄPDF±¨±íÖ®FPDF
RuportÖÐpdf_writer¶ÔÖÐÎĵÄÖ§³Ö²¢²»ºÃ£¬Êä³öµÄÖÐÎÄÏÔʾµÄÊÇÂÒÂë¡£ÉÏÍø²éÁ˺ܶà×ÊÁÏ£¬Ò²Ã»ÓÐÕÒµ½ºÃµÄ½â¾ö·½°¸£¬ÎÞÄÎÖ»ºÃ²é¿´Ô´´úÂ룬µ½µ×ΪʲôRuport×Ô´øµÄPDF¹¤¾ß²»Ö§³ÖÖÐÎÄÊä³ö¡£
Ruport::Formatter::PDF::WriterÖÐÕÒµ½ÒÔÏ´úÂë
metrics = load_font_metrics(font)
metrics = PDF::Writer::FontMetrics.open(font)
PDF::Writer::FontMetrics::METRICS_PATH = [ File.join(File.dirname(File.expand_path(__FILE__)), 'fonts') ]
ÔÀ´METRICS_PATH=%RUBY_HOME%\lib\ruby\gems\1.8\gems\pdf-writer-1.1.8\lib\pdf\writer\fonts
ÔÚ´Ë·¾¶Ï´æÔÚµÄafm×ÖÌåÎļþ¾ù²»Ö§³ÖÖÐÎÄ£¬ÓÚÊÇ¿ªÊ¼½«Ä¿±êתÏòÌí¼ÓÒ»¸öÖ§³ÖÖÐÎÄµÄ *.afm×ÖÌåÎļþ¡£ÎÞÄÎÎļþÕÒµ½ÁË£¬·Åµ½¸Ã·¾¶Ï£¬ÔËÐо¹±¨´íÁË£¨Ò²ÐíÊÇPDF_WRITER²»Ö§³Ö¸ÃÎļþ£©
·ÅÆúÁË´Ë·½·¨£¬°ÑÄ¿±êתÏòFPDF
1£©ÏÂÔØfpdf http://download.csdn.net/source/5608
2£©½âѹµ½RailsÏîÄ¿µÄlibÏÂ
3£©°´Ruby Roportʵ¼ù—¼òµ¥±¨±íϵͳÍê³ÉRuportÓ¦ÓÃ
4£©½ÓÏÂÀ´£¬ÐÞ¸ÄReportOutputController.rb
½« class Ruport::Formatter::PDFÐÞ¸ÄΪÈçÏÂÄÚÈÝ
class Ruport::Formatter::FPDF < Ruport::Formatter::PDF
def pdf_writer
unless @pdf_writer
@pdf_writer = ::FPDF.new
@pdf_writer.extend(PDF_Chinese)
@pdf_writer.AddPage
@pdf_writer.AddGBFont
@pdf_writer.SetFont('GB','', options[:font_size] || 16)
end
return @pdf_writer
end
def render_pdf
output << pdf_writer.Output
end
end
class Pdf < Ruport::Formatter::FPDF
renders :pdf, :for => BaseSqlController
build :data_sheet do
eval(options[:pdfContent])
end
end
5£©ÐÞ¸ÄÊý¾Ý±íreport_templatesÖÐtemplate_contentÄÚÈÝΪ
pdf_writer.SetFont('GB','B',10)
pdf_writer.SetLeftMargin(80)
pdf_writer.Cell(40,10,Iconv.conv('GB2312','UTF-8','²úÆ·±¨±í2'))
pdf_writer.Ln()
pdf_writer.SetFont('GB','',8)
pdf_writer.Cell(40,5,Iconv.conv('GB2312','UTF-8','Ãû³Æ'),1,0,'C')
pdf_writer.Cell(40,5,Iconv.conv('GB2312','UTF-8','Àà±ð'),1,0,'C')
pdf_writer.Cell(40,5,Iconv.conv('GB2312','UTF-8','¼Û¸ñ'),1,0,'C')
pdf_wri
Ïà¹ØÎĵµ£º
¿ª·¢»·¾³
Ruby: Ruby1.9.1
Rails: Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
Ò»¡¢´´½¨Êý¾Ý±íUsers
ÀûÓÃRubyMine×Ô´øµÄScaffold¹¤¾ß´´½¨Êý¾Ý±íUsers£¬Ò²¿ÉÒÔÊÖ¶¯´´½¨
¶þ¡¢´´½¨ControllerºÍView
RubyÏîÄ¿—>ÓÒ¼ü—>Create Model
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎ ......
http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Understanding Ruby Blocks, Procs and Lambdas
Blocks, Procs and lambdas (referred to as closures
in Computer Science) are one of the most powerful aspects of Ruby, and
also one of the most misunderstood. This ......
%{String} ÓÃÓÚ´´½¨Ò»¸öʹÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´®
%Q{String} ÓÃÓÚ´´½¨Ò»¸öʹÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´®
%Q!Some String of “Characters”! <==> ” Some String of \”Characters\” “
%q{String} ÓÃÓÚ´´½¨Ò»¸öʹÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´®
%q!Som ......
rubyÖе¥ÒýºÅºÍË«ÒýºÅµÄÒâÒåÓÐËù²»Í¬£¬Ë«ÒýºÅ°üΧµÄ×Ö·û×÷±äÁ¿Ìæ»»£¬µ¥ÒýºÅ°üΧµÄ±äÁ¿²»×öÌæ»»
Ò²¿ÉÒÔʹÓà %q ºÍ %Q À´Éú³É×Ö·û´®¶ÔÏó¡£%q Ï൱ÓÚµ¥ÒýºÅ£¬%QÏ൱ÓÚË«ÒýºÅ¡£
¾ÙÀýÈçÏ£º
irb(main):010:0> "show trsult: #{1*3}"
=> "show trsult: 3"
irb(main):011:0> 'show trsult: #{1*3}'
=> "show trs ......
±¾ÎÄת×Ô:
http://hi.baidu.com/24xinhui/blog/item/9f52dd34382e11325ab5f553.html
ruby-Óï·¨
2009Äê06ÔÂ20ÈÕ ÐÇÆÚÁù ÉÏÎç 00:21
http://www.blogjava.net/xxllnnn/archive/2009/01/18/251762.html
http://www.cnblogs.com/cnblogsfans/archive/2009/01/24/1380804.html
__setobj__ £¨2009-7-14£©
&nbs ......