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

4

7

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/

Katowice answered 2/6, 2015 at 8:14 Comment(6)
by default rails provides a lot of MIME types to work with. Take a look at this link apidock.com/rails/Mime#13-Default-Mime-TypesWickner
for generating pdf i would suggest you to go with wicked_pdf gem, as far as html you don't need any gem for this. For docx i can help you with the codeWickner
Thank you for your advises ! About your help : the application is not for now i just take information about the conception. Thank you for your proposition anyway !Plectrum
Hi and welcome to Stack overflow. Starting a question with "what is the best way" means you are asking us for our opinions. Sadly "primarily opinion-based" questions are no longer allowed on this site because in the past they have led to flame wars that tore apart our community. Instead we prefer questions that have specific "right" answers.Munmro
Also, even when you cut out the opinion on what is the best tool - your question is asking us for a library or tool for PDFs. We also don't allow questions like that because you can find them via google, and the answer will become stale quickly as tools change over time... and we want our questions here to be forever. So we prefer you to do your research, try out a few tools and see which one is right for you. If you get stuck using one... then come back to us and we'll help you bug-fix.Munmro
Ok i didn't know. i won't do that in the future.Plectrum
R
9

For authoring PDF files

I would go with Prawn over the Wicked-PDF (though licensing concerns may force your hand there).

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.

Rameses answered 3/6, 2015 at 0:9 Comment(2)
Thank you for the info PDF combine i didn't know that gemPlectrum
I be careful about using prawnpdf, its great but its still licensed under GPL. They can't seem to get it moved to MIT. Any one thinking about bringing this into a work repository might cause some lawyers grief.Renie
S
3

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.

Squadron answered 23/10, 2019 at 7:20 Comment(0)
M
2

I use those gems at work, and they are pretty fine, if it can help.

For the html, a simple render could work.

Melaniamelanic answered 2/6, 2015 at 8:43 Comment(0)
D
0

you can have a look at Ruby toolbox for available gems for pdf generation.i will recommend Prawn,as i have used it myself and very easy simple code to generate pdf is needed.

for example:-

require "prawn"

Prawn::Document.generate("hello.pdf") do
  text "Hello World!"
end

Use the Ruby Toolbox to find other gems for docx/html as well :)

Discophile answered 2/6, 2015 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.