
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
- Convert MSG to PDF in Ruby using Cloud REST API
- MSG to PDF Conversion using Advanced Options in Ruby
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:
- Create an instance of ConvertApi
- Create a ConvertSettings object
- Set the input MSG file path and output format to
"pdf" - Define the output folder (e.g.,
"conversion") - Build a ConvertDocumentRequest using the settings
- 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:
- Create an instance of ConvertApi
- Build a ConvertDocumentRequest with ConvertSettings
- Set the input MSG path and output format to
"pdf" - Instantiate MsgLoadOptions and configure
display_header,display_email_address, andpreserve_original_date - Create PdfConvertOptions and adjust options such as
center_window,display_doc_title, margins,image_quality, etc. - Provide
load_options,convert_options, andoutput_path - 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.