setrtrust.blogg.se

Rails pdfkit
Rails pdfkit









rails pdfkit
  1. Rails pdfkit how to#
  2. Rails pdfkit install#

Part of my app involves generating pdf's from html web pages. So far everything is up and running smoothly except for one issue. (If we were doing this with a Rails 2 app this would go in the environment configuration file.) We’ll modify the file so that the application uses the PDFKit middleware. Rails - PDFkit not working in production Ask Question 1 Im working on deploying my rails application on an Ubuntu server with Apache2 and Passenger. The API embraces chainability, and includes both low level functions as well as abstractions for higher level functionality. In a Rails 3 application this is done in the /config/application.rb file.

Rails pdfkit how to#

You can read up on how to do that in their comprehensive Readme. PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy. This ensures the stylesheet_link_tag and font-url helpers output the absolute path including your domain name rather than just the relative path.ĭepending on the complexity of your requirements, you might want to set up Grover as a middleware. The easiest way to enable this is to set config.asset_host in your app configuration. Since Grover uses Chromium which runs external of your Rails app, you need to reference all your assets with absolute paths instead of relative paths.

rails pdfkit

Rails pdfkit install#

2) Run bundle install 3) Install wkhtmltopdf, and run which. This will also allow you to reuse CSS from your app rather than having to write specific CSS just for your PDF exports. Solved-PDFKit usage Rails 5-ruby 1) Add gem pdfkit gem wkhtmltopdf-binary to Gemfile. So your PDF will look exactly how your page looks in Google Chrome's print preview. It uses Puppeteer and Chromium to "print" an HTML page into a PDF. 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. They're good libraries but the underlying wkhtmltopdf doesn't support modern CSS features such as custom properties or grid so you might find yourself unable to use any of the existing CSS in your app to style your PDF export. For me, I'm running Rails/PDFkit in a Docker container running Ubuntu, and needed to install fonts locally to Ubuntu. I'd highly advise against using both those gems. PDFKit comes with a middleware that allows users to get a PDF view of any page on your site by appending. They both use a command line utility called wkhtmltopdf under the hood which uses WebKit to render a PDF from HTML. However with the right setup, it's possible to take the pain out of it!Ī couple of popular gems to convert HTML to PDF in Rails are PDFKit and WickedPDF. Exporting to PDF from HTML can be a bit of a can of worms, especially with CSS not quite working the way it does in a web browser.











Rails pdfkit