2012-03-13 54 views
1

同时使用wkhtmltopdfWickedPdf停在我的本地系统

undefined method `pdf_from_string' for #<WickedPdf:0x7f4b82a369c8> 

我wicked_pdf.rb

WickedPdf.config = { 

:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', 
:layout => "pdf.html", 
:margin => { :top=> 40, 
       :bottom => 20, 
       :left=> 30, 
       :right => 30}, 
:header => {:html => { :template=> 'layouts/pdf_header.html'}}, 
:footer => {:html => { :template=> 'layouts/pdf_footer.html'}} 
# :exe_path => '/usr/bin/wkhtmltopdf'} 

在命令行

wkhtmltopdf google.com google.pdf 

是生成PDF我得到这个错误的工作工作正常。

+0

你为什么不以你的问题添加红宝石标签..可能帮助 – ppant 2012-03-14 11:50:28

回答

0

“pdf_from_string”表示它使得STRING成为pdf。 所以要使这个方法工作,它应该接收字符串。

<WickedPdf:0x7f4b82a369c8> - it is an object. 

它应该是这样的:

pdf_from_string("<p>some html code</p>") 
0

类本身调用pdf_from_string的时候,而不是一个实例,您将得到这个消息。

WickedPdf.pdf_from_string('<p>some html code</p>') 

不会然而工作,:

WickedPdf.new.pdf_from_string('<p>some html code</>') 

会,因为new返回一个实例,然后你可以调用pdf_from_string上。

这是与此相同:

pdf_generator = WickedPdf.new 
pdf = pdf_generator.pdf_from_string('<p>some html code</p>')