-
Notifications
You must be signed in to change notification settings - Fork 2
Home
gem install pdfkit
See https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF-and-WKHTMLTOIMAGE
This can happen when You use wkhtmltopdf in oder version then You should (for example from Ubuntu repository), to fix this You must use version from http://code.google.com/p/wkhtmltopdf/downloads/list or this from PDFkit/bin
The Unix packages x11-libs/libXext and x11-libs/libXrender are dependencies needed to use PDFKit. Here are the instructions to get pdfkit up and running in the AppCloud.
-
On Engine Yard's AppCloud, they use gentoo. Let's install the libs. Type into your console:
sudo emerge libXext libXrender
-
After you install the Unix packages, complete the following
cd /usr/local/bin/
If you have ran the pdfkit --install-wkthmlpdf already and it isn't working do:
sudo rm wkhtmltopdf
- Lastly type into console:
For 32-bit instance:
curl http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_beta5-static-i386.tar.lzma | lzcat - | sudo tar xfv -
sudo mv wkhtmltopdf-i386 wkhtmltopdf
For 64-bit instance:
curl http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2 | bunzip2 - | sudo tar xvf -
sudo mv wkhtmltopdf-amd64 wkhtmltopdf
-
Disable the PDFKit middleware so that your controller handles the generation of the PDF.
-
Register PDF as a mime-type in environment.rb
Mime::Type.register "application/pdf", :pdf
-
In your controller, cache pages just like normal with
caches_page :show
-
create a format.pdf call in your respond_to block and init a new PDFKit object, pass in the url to the current action and call
to_pdf
on it.respond_to do |format| format.html # show.html.erb format.pdf { render :text => PDFKit.new( post_url(@post) ).to_pdf } end
Now in your cache directory you'll create two cache files - one .html
and one .pdf
.
PDFKit does some rather expensive operations to keep the API simple, like parsing your html to extract stylesheets.
If you need to speed it up see this gist https://gist.github.com/1330326