How to Convert EML files to PDF Online using REST API in Ruby

How to Convert EML files to PDF Online using REST API in Ruby

An EML file is a format that is used by many email clients to save emails on your PC or laptop. You can convert EML files into PDF to secure, share and transform emails to PDF format to save EML as PDF file. In this article, I am going to explain how to convert EML files to PDF online using REST API in Ruby. This will help you to automate the conversion of email messages on the cloud within rails application.

The following topics shall be covered in this article:

EML to PDF Conversion REST API and Ruby SDK

To convert EML to PDF format, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API . Our Cloud APIs allows you to convert your documents of popular supported file format to any format you need. You can easily convert more than 50 types of documents such as Word, PowerPoint, Excel, PDF, HTML, etc.

You can install GroupDocs.Conversion into your Ruby application. Use the below command in rails console for converting EML to PDF using gem:

gem install groupdocs_conversion_cloud

Before you proceed, quickly get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, please add in the code as shown below:

Convert EML File to PDF using REST API in Ruby

You can convert EML file to PDF with just a few lines of code by following the below mentioned steps.

  • Create an instance of ConvertApi
  • Create an instance of the ConvertSettings
  • Set the input eml file path and output fileformat as “pdf”
  • Provide the output file path as “email-message-format”
  • Create ConvertDocumentRequest with ConvertSettings
  • Finally, call the convert_document() method with ConvertDocumentRequest

The following Ruby code follows the above steps and converts the email EML format to PDF file:

Convert EML to PDF using Advanced Options in Ruby

EML files can be converted to PDF by setting loading options and also by defining the fields to show or hide in the converted PDF.

  • First, create an instance of the ConvertApi
  • Now, create ConvertDocumentRequest with ConvertSettings
  • Set input eml file path and the output file format as “pdf”
  • Now, create an instance of the EmlLoadOptions
  • Set display_header, display_email_address and preserve_original_date loadOptions
  • Next, create an instance of the PdfConvertOptions
  • Then, set various convert options such as center_window, display_doc_title, margin, image_quality and other options as shown below.
  • Provide load_options, convert_options and output_path settings.
  • Create ConvertDocumentRequest with ConvertSettings
  • Finally, call the convert_document() method with ConvertDocumentRequest

The following Ruby code follows the above steps and converts the email EML file to PDF format. Now, you also have the option to hide or show different fields of email messages:

Online EML to PDF Converter

How to convert EML files to PDF online? Please try the following free online EML to PDF conversion tool, which is developed using the above API.

Conclusion

In this article, we learned how to:

  • Convert the EML files to PDF programmatically on the cloud;
  • EML format to PDF using advanced options in Ruby REST API;

You may learn more about GroupDocs.Conversion Cloud API from the documentation. We also have an API Reference section that lets you visualize and communicate with our APIs directly through the browser.

Ask a question

If you have any questions about EML to PDF converter, please feel free to ask us on the Free Support Forum.

See Also