How to Convert Excel to PDF using REST API in Ruby

How to Convert Excel to PDF using REST API in Ruby

Excel is commonly used to store information in a series of separate pages within business organizations. In certain cases, you may need to convert Excel to PDF programmatically. In this article, we will learn how to convert Excel to PDF using REST API in Ruby.

The following topics shall be covered in this article:

Excel to PDF Conversion REST API and Ruby SDK

For converting Excel to PDF, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. Please install it using the following command in the console:

gem install groupdocs_conversion_cloud

Please get your Client ID and Secret from the GroupDocs Dashboard before following the below mentioned steps. Once you have your Client ID and Client Secret, add these in the ruby application code as shown below:

Convert Excel to PDF using File Conversion API in Ruby

We will convert Excel sheet to PDF file by following the simple steps as given below. You can upload the excel files to the cloud using the code example. As a result, the uploaded Excel will be available in the files section of the dashboard on the cloud. Now, let’s convert XLSX to PDF document programmatically by following the steps as given below:

  • Firstly, create an instance of the ConvertApi.
  • Next, create an instance of the ConvertSettings.
  • Then, set the input excel file path.
  • And, assign “pdf” to format settings.
  • Also, provide the output file path.
  • After that, create ConvertDocumentRequest with ConvertSettings as argument.
  • Finally, call the ConvertApi.convertDocument() method with ConvertDocumentRequest.

The following code example shows how to convert XLSX to PDF document using a REST API in Ruby:

The above sample code will save the converted PDF file on the cloud. You can download converted PDF file using the following code example.

Convert Range of Pages from Excel to PDF in Ruby

We can convert a range of pages from XLSX to PDF documents programmatically by following the steps given below:

  • Firstly, create an instance of the ConvertApi.
  • Next, create an instance of the ConvertSettings.
  • Then, set the input PDF file path.
  • And, assign “xlsx” to format.
  • Also, provide the output file path.
  • Next, create an instance of the PdfConvertOptions.
  • Then, set a page range to convert from start page number as fromPage and total pages to convert as pagesCount.
  • After that, create ConvertDocumentRequest with ConvertSettings as argument.
  • Finally, call the ConvertApi.convertDocument() method with ConvertDocumentRequest.

The following code example shows how to convert a range of pages from PDF to XLSX using a REST API in Ruby:

Online Excel to PDF Converter for Free

Please try the following free online XLSX conversion tool from any device with a modern browser like Chrome and Firefox. It has been developed using the Groupdocs.Conversion API.

Conclusion

In this article, we have learned how to convert Excel to PDF on the cloud. We have also seen how to convert specific pages or a range of pages from XLSX to PDF using Ruby. This article also explained how to programmatically upload a XLSX file to the cloud and then download the converted PDF file from the Cloud. Besides, you can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

If you have any questions about Excel to DOCX Converter, please feel free to ask in GroupDocs.Conversion Forum and it will be answered within a few hours.

See Also