Ruby Ruportʵ¼ù—ÖÐÎÄPDF±¨±íÖ®PRAWN
FPDFÄÜÖ§³ÖPDFµÄÖÐÎÄ´òÓ¡£¬È»¶øÈ´´æÔÚ²»ÉٵIJ»ÈçÒâÖ®´¦£¬¾ÝÎÒÄ¿Ç°µÄʹÓã¬×ܽá³ö¼¸µã£º
1£©FPDFÌṩµÄPdf_Chinese×ÖÌ壬½«GBÕâÖÖ×ÖÌåдÈëÁË´úÂëÖУ¬ÈôÎÒÃÇÏ£ÍûÒýÈëÆäËûµÄÖÐÎÄ×ÖÌ壬Ôò²»ÄÜ·½±ãµØʹÓÃ
2£©FPDFÊä³öµÄÊý×Ö²¢²»ÃÀ¹Û£¬²»ÈçRuport::Formatter::PDF×Ô´øµÄ×ÖÌå
3£©FPDFÌṩµÄ·½·¨²¢²»¶à£¬¶ÔÓÚÒ»°ãµÄ±¨±í´òÓ¡£¬ÓõÄ×î¶àµÄÒ²ÐíÊÇ Cell·½·¨£¬µ«Èç¹ûÁ¬Ò»¸öÆÕͨµÄ±¨±í´òÓ¡¶¼ÐèÒªÄܹý´úÂë¿ØÖÆ»»ÐС¢»Ö±Ïß¡¢Ð´µ¥Ôª¸ñ£¬ÄǾÍÌ«²»·½±ãÁË
PrawnÒ²ÊǺôÉù½Ð¸ßµÄÒ»ÖÖRuby PDF±¨±í¹¤¾ß£¬¶ÔÓÚËüºÍ FPDF µ½µ×˸üÓÅÐ㣬Õâ¾ÍÒªÒòÈ˶øÒìÁË£¬FPDFÊÇÓÃPHP±àдµÄPDF¿âµÄÒÆÖ²£¬¶øPRAWNÔò²»ÊÇ Prawn£ºÊ¹ÓÃRubyÉú³ÉPDF¸ü¼ò½Ý ÖÐÓмòµ¥µÄ½éÉÜ
ÏÂÃæÀ´¿´¿´PRAWNÊÇÈçºÎʵÏÖPDFµÄ´òÓ¡µÄ£¨»ù±¾µÄʵÏֲο¼ Ruby Ruportʵ¼ù—¼òµ¥±¨±íϵͳ£©
Ò»¡¢°²×°Prawn
gem install prawn
¶þ¡¢ÐÞ¸Äenviroment.rb
Ìí¼ÓÈçÏÂÒýÓãº
require "prawn"
require 'prawn/layout'
Èý¡¢ÒýÈëºÏÊʵÄÖÐÎÄ×ÖÌå
PrawnÖ§³ÖÍⲿÒýÈëÖÐÎÄ×ÖÌ壬ÀýÈç“¿¬Ìå”
´ÓC:\Windows\FontsϽ«±¾»úÖ§³ÖµÄ×ÖÌåÎļþ(*.ttf)¸´ÖƵ½
%RUBY_HOME%\lib\ruby\gems\1.8\gems\prawn-core-0.8.4\data\fonts
ÔÚ´úÂëÖÐͨ¹ý
@pdf_writer.font"#{::Prawn::BASEDIR}/data/fonts/simkai.ttf"
Ö¸¶¨ÐèÒªÒýÓõÄ×ÖÌå
ËÄ¡¢ÐÞ¸ÄReportOutputController.rb
Ìæ»»Pdf<Ruport::Formatter::PDFΪÈçÏ´úÂ룺
class Ruport::Formatter::PRAWN< Ruport::Formatter::PDF
def pdf_writer
unless @pdf_writer
@pdf_writer = ::Prawn::Document.new
@pdf_writer.font"#{::Prawn::BASEDIR}/data/fonts/simkai.ttf"
end
return @pdf_writer
end
def render_pdf
output<<pdf_writer.render
end
end
class Pdf<Ruport::Formatter::PRAWN
renders :pdf, :for => ReportOutputController
build :data_sheet do
eval(options[:outputContent])
end
end
Îå¡¢±£´ærepoert_templates
¶ÔÓÚtemplate_contentµÄÄÚÈݱ£´æΪÈçÏ£º
pdf_writer.text ("²úÆ·Áбí",
:align=>:center,:size=>15)
pdf_writer.image ("public/images/ruport.jpg",
:at => [0,730],
:height=>50,
:width=>100)
pheader=%w[Àà±ð Ãû³Æ ¼Û¸ñ]
pdata=[]
for i in 0..data.length-1 do
temp=[data[
Ïà¹ØÎĵµ£º
Ç°ÑÔ
ÔÚ¡¶RoutingµÄÔØÈë¡·ÖУ¬ÎÒ´óÖ½éÉÜÁËÒ»ÏÂRailsÖÐ×î¼òµ¥µÄrouteÊÇÈçºÎ¼ÓÔصġ£ÕâƪÎÄÕ£¬ÎÒ½«À´½²Ò»½²RailsϵͳÖиüΪ¸´ÔÓµÄnamed routeºÍÓëRESTfulÏà¹ØµÄresourceÊÇÈçºÎ±»¼ÓÔصġ£ÎªÁ˲»Öظ´Ì«¶àµÄ±ÊÄ«£¬ÕâƪÎÄÕ½«ÔÚÇ°ÎĵĻù´¡ÉϽøÐУ¬Èç¹û·¢ÏÖµ¥¶À¿´´ËÎÄʱ£¬ÓÐÉÙÐíÔÆÀïÎíÀ½¨ÒéÏÈ¿´Ò»¿´ÎÒµÄǰƪÎÄÕ£ºR ......
require 'open-uri'
$NAME_CHARS= (?a..?z).to_a+(?0..?9).to_a
def is_name_used(name)
str=open('http://passport.csdn.net/UserExist.aspx?UserName='+name)
str=str.read
#str=str.encode('GBK','utf-8')
return true if str[/Red/]
end
def enum_names(len=2)
return if len<2
f=File.open(' ......
¿ª·¢»·¾³
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 ......
Bignum
+ ¼Ó
- ¼õ
* ³Ë
/ ³ý
** Ö¸Êý²Ù×÷2**2 Òâ˼ÊÇ2µÄƽ·½
<=> ´óÓÚ, ......