Convert Excel and Word files to PDF Using ruby - ruby-on-rails

I want to convert Excel with multiple sheets and Word files to PDF format as a single file using Ruby.
Is there any Script/Gems/Plugins available to achieve this?

You can use libreconv
https://github.com/ricn/libreconv
You'll need to install libre office on your server, which is straightforward.

There is not a Gem doing all the job. but you can combine some:
For excel files - read data using roo GEM - http://roo.rubyforge.org/
For word files Opening .doc files in Ruby
Convert the data readed in previous steps into html.
Then convert it to pdf using: https://github.com/pdfkit/PDFKit

Related

Rails - Embed XML in PDF

I need to attach a XML file within a PDF file to be PDF/A3 compliant.
I am using rails and so far I had no issues to generate my PDF (using Prawn gem) and my XML separately but I do not know how to "combine" them.
Any ideas ?
Cheers
We have got similar problem and finally decided to follow the below approach
Generate the pdf file using wkhtmltopdf
Use pdftk (https://www.pdflabs.com/tools/pdftk-server/) to attach XML file with pdf

Convert DOCX file to PDF file in Ruby

I'm converting a docx file to PDF using libreconv gem and I want to keep the same fonts that I'm using inside the docx file but the generated PDF does not have the same fonts
What is the solution for this issue?
Or is there any other gem to convert from Docx file to PDF with High quality
I don't want to convert the docx file to HTML first, so PDF KIT and wicked_pdf gems will not work for me
Thanks in advance
Make sure that your fonts are installed in the system where you're running libreconv.
If it's ubuntu-based you can run fc-list - list available fonts to see the list of installed fonts.

Is there an upgrade gem to prawn to covert odf (.odt)?

I've been using the awesome prawn gem in my last few project, but this time I have to covert a odt file (in odf format) to PDF.
I know that there are many gems that can do this, for example docsplit and others, but since I am already using prawn to generate other PDFs in the same app I would really like to know if I could get a way without adding yet another pdf creator type gem...
Does anyone know any resources that could help? Or at least a (really) simple gem that coverts odt to PDF (without possibly having to install anything)?
Thanks in advance...
No, Prawn can't do that. Prawn is just a library for programmatically generating PDF documents.
Best way would be using LibreOffice in a head-less fashion to convert ODF files into PDF.

Parse doc and xls files in ruby

In my rails application, I need to upload some doc/xls files and parse its structure and get information. How can I get data from *.doc or *.xls in maybe xml format or anything else that I can read and parse?
You can parse different types of spreadsheets using the Roo gem. It supports:
OpenOffice
Excel
Google spreadsheets
Excelx
LibreOffice
CSV
From my experience it has some issues with parsing .xls files, however parsing .xlsx files is good.
As for .doc files, you may try using msworddoc-extractor gem or try one of the solutions proposed here.
Update: working with *.docx files - docx and docx-html
Have you seen the Nokogiri gem? http://nokogiri.org/
Very useful for xml parsing
The spreadsheet gem is nice for excel and csv files.
https://github.com/zdavatz/spreadsheet

Prawn gem: How to create the .pdf from an *existing* file (.xls)

Can anybody show me (maybe copy/paste a simple code example) how to create the .pdf file from an existing (.xls) file, using the Prawn gem? (Basically, I'd need the command that "opens" the existing file.)
(I'm asking because the Prawn documentation (http://prawn.majesticseacreature.com/docs/) seems to be gone since quite a while - it's not even usable via Google cache...)
Thanks a lot for any help with this!
Tom
I'd suggest that you break the problem down.
Can you read xls with Ruby? Possibly, but it's flaky at best. However, you can easily read csv, and xls exports nicely to that format.
Can you write a 'table' of values to a prawn pdf? Yes
So, (almost) all you need is a little program that can parse a csv file into a prawn-friendly table-structure and then hand it off to Prawn for generation.
Turns out the Prawn gem cannot handle existing files...
Prawn can be used to render content on top of a PDF. You're talking about .xls, a completely different format.

Resources