How to Convert MSG files to PDF in Ruby

How to Convert MSG files to PDF in Ruby

MSG to PDF conversion is important for creating a backup of all essential emails in an organization. The email format for PDF files does not change as PDF is a safe file format to keep as a backup and cannot be modified. In this article, we will learn how to convert MSG files to PDF in Ruby.

The following topics are covered in this outlook mail MSG files to PDF converter article:

MSG to PDF Conversion Library – API Installation

We will be using the Ruby SDK of GroupDocs.Conversion Cloud API to convert MSG to PDF format. 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 MSG 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 MSG to PDF in Ruby using Cloud REST API

Outlook MSG files can be converted 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 msg file path and output fileformat as “pdf”
  • Provide the output file path as “conversion”
  • Create ConvertDocumentRequest with ConvertSettings
  • Finally, call the convert_document() method with ConvertDocumentRequest

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

MSG to PDF Conversion using Advanced Options in Ruby

Outlook MSG files can be converted to PDF with just a few lines of code by following the below mentioned steps.

  • First, create an instance of the ConvertApi
  • Now, create ConvertDocumentRequest with ConvertSettings
  • Set input msg file path and the output file format as “pdf”
  • Now, create an instance of the MsgLoadOptions
  • 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 MSG file to PDF format. You also have the option to hide or show different fields of email messages:

Online MSG to PDF Converter

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

Summing up

In this article, we have learned:

  • how to convert the MSG files to PDF programmatically on the cloud.
  • how to print MSG to PDF using advanced options in Ruby

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 MSG to PDF converter, please feel free to ask us on the Free Support Forum.

See Also