Ruby pdfkit windows1/28/2024 Mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf Sudo aptitude install openssl build-essential xorg libssl-dev Looking at the installation instructions page we find this snippet of joy labelled ‘Or….’ under Linux (Ubuntu): # first, installing dependencies So what now? Well after a bit of Googling I was starting to get worried, until somebody (I forget where, but thank you!) mentioned that the binaries that can be downloaded from the project’s repo are built against qt and don’t depend on X running! Result! It turns out that the standard wkhtmltopdf package needs the server to have a window manager running and the chances are your server, like this one, doesn’t have a GUI interface. Huh? I then tried to run the command from the command line to see if I could get a more useful error message: $ wkhtmltopdf google.pdfĭamn. Wat!? Looking in the log file: command failed: "/usr/bin/wkhtmltopdf" "-page-size" "Letter" To grab the package, loaded up the site and hit the download button: Internal Server Error. I did a quick sudo apt-get install wkhtmltopdf Very pleased with my new sexy PDF reports I wanted to push my code to the server. First add a line to the Gemfile gem 'pdfkit'Īnd then install the wkhtmltopdf library using brew install wkhtmltopdf And then I tried to deploy to a server… What could be simpler? To get this up and running there were a couple steps. Where the :action option is a path to a view file. Html = render_to_string(:action => './pdf/my_template', :layout => false) In my controller I simply have: def download_pdf The API is perfect: have some HTML, give me a PDF back. I’ve been using the rather excellent PDFKit library on a recent Ruby on Rails project to generate PDF reports.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |