2011-03-28 121 views
0

我安装了PDFKit和wkhtmltopdf。PDFKit不生成正确PDF

在一个动作我呈现一个简单的HTML,如:

<html><body><h1>Hello Internet!</h1></body></html> 

当我跑我的.pdf扩展动作它会产生一个错误的PDF文件。调试PDFKit我到这些行:

result = IO.popen(invoke, "w+") do |pdf| 
    pdf.puts(@source.to_s) if @source.html? 
    pdf.close_write 
    pdf.gets(nil) 
end 

嗯,这是生成我的PDF在那里,它使用一个命令行没有wkhtmltopdf和我的HTML作为输入。

使用中,RDebug我发现,调用值:

"c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-" 

而@ source.to_s是

<html><body><h1>Hello Internet!</h1></body></html> 

好了,我试图用手像这样运行命令:

"c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-" <c:\hello_internet.html> correct.pdf 

显然在hello_internet中有@ source.to_s的内容

运行它会生成正确的pdf。

生成的正确pdf是here,错误是here

我不知道这里可能会出现什么问题。

谢谢。

+0

也许我错了!您是否正在尝试使用pdfkit从没有使用wkhtmltopdf的HTML源代码生成pdf? – tommasop 2011-03-28 08:37:55

回答

0

该解决方案非常简单,并且是PDFKits Github上的bxu689的pull request的对象。