Export PDF files from HTML in Rails application

Tram Ho

Pdf is one of the popular formats today, with the advantage of being high quality and not prone to changing the font or layout of the content. So pdf is often used to store the content after it is completed and use them to exchange online. In some websites, many tasks also need to be stored in pdf format to facilitate the storage of users, so today I wrote this article to create a simple website using Ruby on Rails. PDF export function from web page information with PDFKit gem !!!

Create the Rails application

Create an application called invoices (invoices) and add 2 models:

Then add some sample data to the database by adding the file db/seeds.rb.

Run the rails db: seed command in the terminal to add the sample invoice to the database.

Create controller and view

run rails generate controller Invoices index show to create controllers and views.

app / models / invoice.rb

app / models / line_item.rb

app / controllers / invoicescontroller.rb

def show
@invoice = Invoice.find(params
Share the news now

Source : Viblo