PDFKIT apparently not working because of “wkhtmltopdf”

一笑奈何 提交于 2019-12-21 17:06:42

问题


I'm having trouble generating a PDF out of a html page.

I'm using PDFkit. In the process of installing it, I noticed I needed wkhtmltopdf. So I installed it too. I did everything PDFkit's documentation said to do.. and now I'm getting this error when I try to load the PDF.

Here is the error:

command failed: "/usr/local/bin/wkhtmltopdf" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-"

Any idea of what this could be?

Thanks


回答1:


I have the following configuration in my rails application. I tested it in irb and it worked well.

PDFKit.configure do |config|
  config.wkhtmltopdf = `which wkhtmltopdf`.to_s.strip
  config.default_options = {
    :encoding=>"UTF-8",
    :page_size=>"A4",
    :margin_top=>"0.25in",
    :margin_right=>"1in",
    :margin_bottom=>"0.25in",
    :margin_left=>"1in",
    :disable_smart_shrinking=>false
    }
end

You need to set the path to wkhtmlpdf executable file.




回答2:


I actually got it to work by deleting PDFKit and wkhtmltopdf. And following step by step as mentioned here:

https://github.com/jdpace/PDFKit/

(make sure you install wkhtmltopdf by hand)

Thanks



来源:https://stackoverflow.com/questions/4834044/pdfkit-apparently-not-working-because-of-wkhtmltopdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!