Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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 on rails Ò»²½²½¿ªÊ¼(2)·ÖÒ³ºÍ¼òµ¥²éѯ

ʹÓà will_paginate ½øÐзÖÒ³ºÍ¼òµ¥²éѯ
ÔÚÃüÁîÐÐÏÂʹÓà gem install will_paginate ÃüÁ³öÏÖÏÂÃæ½á¹û°²×°³É¹¦
´ò¿ª books_controller.rb (Äã×Ô¼ºµÄ¿ØÖÆÆ÷)
×¢Ê͵ô²éÕÒÈ«²¿µÄ·½·¨£¬Ê¹ÓÃÏÂÃæµÄ·½·¨£¬ÒѾ­¼¯³É¸ù¾Ýtitle½øÐвéѯ
Ruby´úÂë
#@books = Book.all   
@books = Book.pagina ......

Ruby On Rails 2.0.2Ô´´úÂë·ÖÎö£¨3£© resource


RESTfulµÄ»¯Éí----resource
  µ±È»£¬¹â°ÑRESTfulºÍresource³¶µ½Ò»ÆðËÆºõÏ൱ÏÁÒ壬ÔÚRailsÖУ¬ActionController::Resources³éÏóÁËRESTÖеÄResource£¬ÕâÀÎÒ²»Ì¸RESTµÄÏà¹Ø¸ÅÄî£¬ÍøÉÏ×ÊÁÏÒ»´óÛç¡£ÎÒÃǾÍÀ´¿´¿´RailsÖÐÊÇÈçºÎͨ¹ýResourceÀ´ÇáËÉ£¬¼ò±ãµÄÍê³ÉRESTfulÓ¦Óõİɡ£
  resources.rb
  Ô´´úÂë ......

rubyÔÚwindows 7 cmd ÖÐÏÔʾ²ÊÉ«ÎÄ×Ö

ÏÈ·ÅÉÏÒ»¸öʵÀýµÄbatÎļþ,ÒªÇó¹ÜÀíÔ±ÌØÈ¨ÔËÐÐ:
@echo off
::CMDÀïÏÔʾ²ÊÉ«ÎÄ×Ö
chcp 437>nul&&graftabl 936>nul
if not exist CONFIG.NT copy %WinDir%\System32\CONFIG.NT CONFIG.NT
@cls
echo DEVICE=%WinDir%\System32\ANSI.SYS /x >%WinDir%\System32\CONFIG.NT
@echo.
command /cecho 
com ......

RUBYʵ¼ù—´øÃÜÂë¼ÓÃܵÄÓû§´´½¨¼°ÐÞ¸Ä

¿ª·¢»·¾³
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
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎ ......

rubyÎļþ´ÓÃüÁîÐÐÖнÓÊÕ²ÎÊý£¨È«¾Ö±äÁ¿£ºARGV)


ÏÂÎÄת×Ô£º
http://www.cnblogs.com/watir/archive/2009/04/25/1443440.html
rubyÎļþ´ÓÃüÁîÐÐÖнÓÊÕ²ÎÊý
ÔÚÃüÁîÐз½·¨Ö´ÐÐrubyÎļþʱ£¬ÐèÒª´ÓÃüÁîÐÐÖд«Èë²ÎÊý£¬¿ÉÒÔʹÓÃÈ«¾Ö±äÁ¿£ºARGV
ÈçÓÐruby Îļþtest.rb,ÄÚÈÝÈçÏ£º
1 def hello(a)
2   puts a
3 end

5  ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ