


We have a Passenger environment setup on our production server, and it spawns multiple ruby processes to handle requests. Viewed 4k times 0 I have managed installing PDFKit and wkhtmltopdf on. This same problem does not exist in our production environment. Ask Question Asked 4 years, 2 months ago. wkhtmltopdf would then make another request to our same development server to render the page. Then during that action we shelled out to wkhtmltopdf.
#Rails pdfkit pdf#
The problem we had in that environment is that the first request would come in when we clicked the pdf button. PDFs From Ruby or Rails Prawn PDFKit wickedpdf Apr 24, 2015. In our development environment we are using WebBrick to serve our pages, and that server is single threaded. After 30 minutes of struggling Dustin was able to identify the problem. We figured that would be enough to make things work, but to our surprise the page hung when we pressed the pdf button.
#Rails pdfkit update#
Output_pdf = "output_#Ĥ.) Update the view to send pdf print requests to the create_product_pdf action. Also, for some stupid reason I had to put quotes around a font that normally does not need this at all in css for wkhtmltopdf to 'see it', like this: font-family: 'serif' None of this is obvious and it's difficult to debug.
#Rails pdfkit install#
We did the following things to create our spike:ġ.) Put the wkhtmltopdf shell script into our RAILS_ROOT/script directory.Ģ.) Create a destination pdfs folder in our RAILS_ROOT/public directory.ģ.) Update routes and add the following action to our products controller. For me, I'm running Rails/PDFkit in a Docker container running Ubuntu, and needed to install fonts locally to Ubuntu. They both use a command line utility called wkhtmltopdf under the hood which uses WebKit to render a PDF from HTML. Our strategy was to send print requests to an action which uses wkhtmltopdf to render a different action in our application, designed for this purpose. A couple of popular gems to convert HTML to PDF in Rails are PDFKit and WickedPDF. Our next step was to spike the pdf creation logic into our application. Adding the print-media-type flag used the print stylesheet, and putting the source_url in quotes allowed for crazy url strings to work properly. Internally, PDFKit uses wkhtmltopdf (WebKit HTML to PDF), an engine that will take HTML and CSS, render it using WebKit, and output it as a PDF with high. wkhtmltopdf -print-media-type "" output.pdfĮverything worked great. Wkhtmltopdf is a simple shell utility that converts html to pdf using the webkit rendering engine, and Qt.Īfter downloading the application we did a quick test to prove if wkhtmltopdf would work well for us. We queried the Atomic Brain Trust for advice and were told to check out wkhtmltopdf. Earlier this week Dustin Tinney and I needed to add simple pdf generation support to a Rails application.
