9

i'm using pdfkit for generating pdf when i generate pdf it gives me following error.

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

Any help?

  • Ateq
Muhammad Ateq Ejaz
  • 1,845
  • 20
  • 22

5 Answers5

6

Hello Guys i serached it on google and find answer on a blog.Thanks guys.

Solution is here.
(1)# first, installing dependencies
 $sudo aptitude install openssl build-essential xorg libssl-dev

(2)# for 64bits OS Run one by one following commands.

$sudo wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
$sudo tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
$sudo mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf 
$sudo chmod +x /usr/local/bin/wkhtmltopdf

Finally Go to your rails app/config/initializer Folder and create new file pdfkit.rb and paste following code in it.

PDFKit.configure do |config|
   config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf' if Rails.env.production?
end

Thats it.Now your pdf file will be download. Also visit for further information http://www.stormconsultancy.co.uk/blog/development/generating-pdfs-in-rails-with-pdfkit-and-deploying-to-a-server/

Thanks.

Muhammad Ateq Ejaz
  • 1,845
  • 20
  • 22
2

Also Guys if you want to to get your PDF View as it looks in your Web Page copy the following code in your config/initializer/pdfkit.rb(create this file in initializer folder)

PDFKit.configure do |config| 
config.wkhtmltopdf ='/usr/local/bin/wkhtmltopdf'
config.default_options = {
   :encoding=>"UTF-8",
   :page_size=>"Ledger",
   :zoom => '1.3',
   :disable_smart_shrinking=>false
}
end

Plese check this link for more ":page_size "attributes

http://stackoverflow.com/questions/6394905/wkhtmltopdf-what-paper-sizes-are-valid

And discover new options by visiting this link

http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html

Hope This all will help you. Thanks.

Muhammad Ateq Ejaz
  • 1,845
  • 20
  • 22
  • I had a big problem with pdfkit in production and I lost few hours fixing and your section 'config.default.options' solved my problem, thank you! – Nezir Sep 09 '17 at 17:42
0

make sure you have the right binary version of bit according to your operating system. I had experienced a wrong version problem when I use the 32 bit binary onto a 64bit ubuntu.

Yakob Ubaidi
  • 1,846
  • 2
  • 20
  • 23
0

you need to upgrade to wkhtmltopdf ( 0.12.2.1 woked for me)

http://wkhtmltopdf.org/downloads.html

ubuntu 14.04 users may get into dependancy problem when installing https://askubuntu.com/a/625225/106182

Community
  • 1
  • 1
equivalent8
  • 13,754
  • 8
  • 81
  • 109
0

In case of you are calling through rails controller, make sure that you set layout false.

Salma Gomaa
  • 952
  • 1
  • 13
  • 18