Generating PDFs in plain Ruby can be a lot of work. Instead, consider generating PDFs from HTML using PDFKit.

Read more at the source