How to Convert MSG files to PDF in Ruby

How to Convert MSG files to PDF in Ruby

MSG to PDF conversion is essential for backing up critical emails. PDF is a secure, non‑editable format, making it ideal for long‑term storage. In this article we’ll show how to convert MSG files to PDF in Ruby.

The following topics are covered in this Outlook MSG to PDF converter guide:

MSG to PDF Conversion Library – API Installation

We will use the Ruby SDK of GroupDocs.Conversion Cloud API to convert MSG to PDF. The cloud API supports over 50 document types, including Word, PowerPoint, Excel, PDF, HTML, and more.

Install GroupDocs.Conversion in your Ruby project with this command:

gem install groupdocs_conversion_cloud

Before you begin, obtain your Client ID and Client Secret from the dashboard — see the instructions at get your Client ID and Client Secret. Add the credentials to your code as shown below:

Convert MSG to PDF in Ruby using Cloud REST API

Convert Outlook MSG files to PDF with just a few lines of Ruby code:

  1. Create an instance of ConvertApi
  2. Create a ConvertSettings object
  3. Set the input MSG file path and output format to "pdf"
  4. Define the output folder (e.g., "conversion")
  5. Build a ConvertDocumentRequest using the settings
  6. Call the convert_document() method

The sample code below demonstrates these steps and also lets you hide or show specific email fields:

MSG to PDF Conversion using Advanced Options in Ruby

For finer control over the PDF output, follow these steps:

  1. Create an instance of ConvertApi
  2. Build a ConvertDocumentRequest with ConvertSettings
  3. Set the input MSG path and output format to "pdf"
  4. Instantiate MsgLoadOptions and configure display_header, display_email_address, and preserve_original_date
  5. Create PdfConvertOptions and adjust options such as center_window, display_doc_title, margins, image_quality, etc.
  6. Provide load_options, convert_options, and output_path
  7. Call the convert_document() method

The Ruby example below applies these advanced settings:

Online MSG to PDF Converter

How to convert MSG files to PDF online? Use our free online MSG to PDF conversion tool, built on the same API:

free online MSG to PDF conversion tool

Summing up

In this article we covered:

  • Programmatic conversion of MSG files to PDF using GroupDocs Cloud
  • Advanced conversion options for customizing PDF output in Ruby

Explore more about GroupDocs.Conversion Cloud API in the documentation and test the API directly via the API Reference.

Ask a question

If you have questions about the MSG to PDF converter, visit our Free Support Forum.

See Also