How to convert Excel XLSX to PDF in Ruby

Today’s tutorial covers a super simple way to convert XLS and XLSX files into PDFs using a free Cloudmersive API. Let’s begin.

To start we add the Document and Conversion API to Ruby’s Gemfile:

gem 'cloudmersive-convert-api-client', '~> 1.3.3'

Now all we have to do is call convert_document_autodetect_to_pdf with the following snippet:

# load the gem
require 'cloudmersive-convert-api-client'
# setup authorization
CloudmersiveConvertApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
end
api_instance = CloudmersiveConvertApiClient::ConvertDocumentApi.newinput_file = File.new("/path/to/file") # File | Input file to perform the operation on.begin
#Convert Document to PDF
result = api_instance.convert_document_autodetect_to_pdf(input_file)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ConvertDocumentApi->convert_document_autodetect_to_pdf: #{e}"
end

All set! Please note that this function allows almost any document type to be converted into PDF including PPTX and DOCX. The API itself can be used for a large array of document editing and conversion tasks, so be sure to check out our documentation section for more details.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store