In my Job Management application I would like to prepare an A4 page receipt to customer.
Thus, I need to print somehow Job
model's details to a single A4 PDF page.
Are the any built-in tools in Rails for this purpose ?
If no, what would be the best way to go ?
Basically there is two options: (any PDF creation requires a gem - no default PDF creation for rails).
Create a pure PDF using Prawn, You have to do all the formatting using the Prawn API
Create a HTML version of your receipt and convert it to PDF, One of the better gems to do this is PDFkit. which uses a web-kit powered browser engine.
They both work good, For one page documents I usually use PDFkit to convert HTML and for larger documents that are going have lots of pages I use Prawn because it gives you a smaller file size and handles multiple pages better.
My suggestion would be to make a HTML receipt and display it on the screen and give the user an option to save a PDF version using PDFkit.
EDIT: windows install. (not tested - windows and I have parted company.)
Download the windows installer for wkhtmltopdf: win-wkhtmltopdf
now create an initializer file, e.g. config/intializers/pdfkit_config.rb
in pdfkit_config.rb set the absolute path to wkhtmltopdf on your local machine:
for your production ENV you can actually just have a copy of wkhtmltopdf in you repo, a unix version of course. (remember to chmod +x it before you git add it)