Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to generate PDF/HTML/DOCX in Ruby/Rails

I need to create an app which makes auto-generated CVs from fields. I need to convert them in PDF/HTML/DOC, but there are many gems available.

Which gem do you think is the most appropriate in order to make CV in PDF, HTML and DOC formats?

I found prawn for PDF, but is it the most appropriate to make CV-like PDF?

Thank you in advance.

EDIT : I found a gem similar to Prawn but for docx maybe that could interest you. https://github.com/trade-informatics/caracal/

like image 219
Théo Capdet Avatar asked Jun 02 '15 08:06

Théo Capdet


2 Answers

For authoring PDF files

I would go with Prawn over the Wicked-PDF.

I know wicked is more convenient, but Prawn is both native and more flexible.

Wicked depends on wkhtmltopdf and uses systems call - and system calls can cause issues with concurrency and are expensive as far as performance goes.

Which ever one your using, I would probably add CombinePDF into the mix. (I'm biased - I'm the author of the gem)

This will allow you to use template PDF files - so you can write your CV using Prawn or Wicked and throw it over a beautifully designed template using the CombinePDF gem.

CombinePDF could also be used to create simple text objects, number pages or write tables...

require 'combine_pdf'
pdf = CombinePDF.new
pdf.new_page.textbox "Hello World!", font_size: 18, opacity: 0.75
pdf.save 'test.pdf' # use pdf.to_pdf to render the PDF into a String object.

...but I think Prawn is a better tool for authoring, while CombinePDF is a great complementing library that can add pre-made content and design:

require 'combine_pdf'
# get a "stamp" or page template.
# the secure copy will attempt to change the PDF data to avoid name conflicts.
template = CombinePDF.load(template_file_path).pages[0].copy(true)
# move the Prawn document into CombinePDF
pdf = CombinePDF.parse prawn_document.render
# add the template to each page, putting the template on the bottom
# (#>> for bottom vs. #<< for top)
pdf.pages.each {|page| page >> template}
# save the pdf file
pdf.save 'final.pdf' # or render to string, for sending over HTTP: pdf.to_pdf

As for docx, I am clueless... frankly, it's a proprietary format that's usually buggy when reverse-engineered. I would avoid it and let people copy and paste off the HTML if they really wanted.

like image 55
Myst Avatar answered Sep 22 '22 06:09

Myst


I always use Prawn for PDF and Caracal for DOCX.

I believe the creator of Caracal was inspired by the ease of use of Prawn.

like image 25
Toby 1 Kenobi Avatar answered Sep 19 '22 06:09

Toby 1 Kenobi