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'
endapi_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.
