PDFKIT apparently not working because of “wkhtmlto

2020-07-13 06:59发布

问题:

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