
You can easily convert your emails and Outlook messages to PDF documents using Node.js on the cloud. Conversion of emails and Outlook messages to PDF enables you to keep records or share important emails and attachments in a portable form. As a Node.js developer, you can convert EML and MSG files to PDF documents programmatically. In this article, you will learn how to convert EML and MSG files to PDF documents using a REST API in Node.js.
The following topics shall be covered in this article:
- EML to PDF Conversion REST API and Node.js SDK
- Convert EML to PDF using a REST API in Node.js
- MSG to PDF Conversion using a REST API in Node.js
- Convert Email Attachments to PDF using REST API in Node.js
EML to PDF Conversion REST API and Node.js SDK
For converting EML and MSG files to PDF, I will be using the Node.js SDK of GroupDocs.Conversion Cloud API. It is a platform-independent document and image conversion solution. It allows you to seamlessly convert your documents and images of any supported file format to any format you need. You can easily convert between over 50 types of documents and images such as Word, PowerPoint, Excel, PDF, HTML, CAD, raster images, etc. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document conversion family members for the Cloud API.
You can install GroupDocs.Conversion Cloud to your Node.js project using the following command in the console:
npm install groupdocs-conversion-cloud
Please 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:
global.clientId = "112f0f38-9dae-42d5-b4fc-cc84ae644972"; | |
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618"; | |
global.myStorage = ""; | |
const config = new groupdocs_conversion_cloud.Configuration(clientId, clientSecret); | |
config.apiBaseUrl = "https://api.groupdocs.cloud"; |
Convert EML to PDF using a REST API in Node.js
You can convert your emails to PDF documents programmatically on the cloud by following the simple steps given below:
- Upload the EML file to the cloud
- Convert EML to PDF using Node.js
- Download the converted PDF file
Upload the EML File
Firstly, upload the EML file to the cloud using the following code sample:
// open file in IOStream from local/disc. | |
var resourcesFolder = 'C:\\Files\\sample.eml'; | |
// read file | |
fs.readFile(resourcesFolder, (err, fileStream) => { | |
// construct FileApi | |
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config); | |
// create upload file request | |
var request = new groupdocs_conversion_cloud.UploadFileRequest("sample.eml", fileStream, myStorage); | |
// upload file | |
fileApi.uploadFile(request); | |
}); |
As a result, the uploaded EML file will be available in the files section of your dashboard on the cloud.
Convert EML to PDF using Node.js
You can easily convert emails from EML files to PDF documents programmatically by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the EML file path
- Assign “pdf” to the format
- Create an instance of the EmlLoadOptions
- Set various properties such as displayHeader, displayEmailAddress, etc.
- Assign EmlLoadOptions to ConvertSettings
- Create an instance of the PdfConvertOptions
- Set various properties such as centerWindow, MarginTop, MarginLeft, etc.
- Assign PdfConvertOptions to ConvertSettings
- Provide the output file path
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert an EML file to a PDF document using a REST API in Node.js.
// initialize convert api | |
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret); | |
// define convert settings | |
var settings = new groupdocs_conversion_cloud.ConvertSettings(); | |
settings.storageName = myStorage; | |
settings.filePath = "sample.eml"; // input file | |
settings.format = "pdf"; // output format | |
// define eml load options | |
var loadOptions = new groupdocs_conversion_cloud.EmlLoadOptions(); | |
loadOptions.displayHeader = true; // display email header | |
loadOptions.displayFromEmailAddress = true; // display "from" email address | |
loadOptions.displayToEmailAddress = true; // display "to" email address | |
loadOptions.displayEmailAddress = true; // display email address | |
loadOptions.displayCcEmailAddress = true; // display "cc" email address | |
loadOptions.displayBccEmailAddress = true; // display "bcc" email address | |
settings.loadOptions = loadOptions; | |
// define pdf convert options | |
let convertOptions = new groupdocs_conversion_cloud.PdfConvertOptions(); | |
convertOptions.centerWindow = true; // set position of the document's window. Default: false. | |
convertOptions.marginTop = 50; // top margin | |
convertOptions.marginLeft = 50; // left margin | |
settings.convertOptions = convertOptions; | |
settings.outputPath = "output.pdf"; | |
// create convert document request | |
var request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings); | |
// convert document | |
convertApi.convertDocument(request); | |
console.log("Document converted successfully: " + response[0].url); |

Convert EML to PDF using a REST API in Node.js
Download the Converted File
The above code sample will save the converted PDF file on the cloud. You can download it using the following code sample:
// construct FileApi | |
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config); | |
// create donwload file request | |
let request = new groupdocs_conversion_cloud.DownloadFileRequest("output.pdf", myStorage); | |
// download file | |
let response = await fileApi.downloadFile(request); | |
// save in your working directory | |
fs.writeFile("C:\\Files\\output.pdf", response, "binary", function (err) { }); | |
console.log(response); |
MSG to PDF Conversion using REST API in Node.js
You can easily convert Outlook MSG files to PDF documents programmatically by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the MSG file path
- Assign “pdf” to the format
- Provide the output file path
- Create an instance of the MsgLoadOptions
- Set various properties such as displayCcEmailAddress, displayBccEmailAddress, etc.
- Assign load options to ConvertSettings
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert an MSG file to a PDF document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.
// initialize convert api | |
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret); | |
// define convert settings | |
var settings = new groupdocs_conversion_cloud.ConvertSettings(); | |
settings.storageName = myStorage; | |
settings.filePath = "sample.msg"; // input file | |
settings.format = "pdf"; // output format | |
// define eml load options | |
var loadOptions = new groupdocs_conversion_cloud.MsgLoadOptions(); | |
loadOptions.displayCcEmailAddress = false; // display "cc" email address | |
loadOptions.displayBccEmailAddress = false; // display "bcc" email address | |
settings.loadOptions = loadOptions; | |
settings.outputPath = "output.pdf"; | |
// create convert document request | |
var request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings); | |
// convert document | |
convertApi.convertDocument(request); | |
console.log("Document converted successfully: " + response[0].url); |

MSG to PDF Conversion using REST API in Node.js
Convert Email Attachments to PDF using REST API in Node.js
You can easily convert email attachments to PDF documents programmatically by following the steps mentioned below:
- Create an instance of the ConvertApi
- Create an instance of the ConvertSettings
- Set the MSG file path
- Assign “pdf” to the format
- Provide the output file path
- Create an instance of the MsgLoadOptions
- Set the convertAttachments property to true
- Assign load options to ConvertSettings
- Create ConvertDocumentRequest with ConvertSettings
- Convert by calling the convertDocument() method with ConvertDocumentRequest
The following code example shows how to convert email attachments to a PDF document using a REST API in Node.js. Please follow the steps mentioned earlier to upload and download a file.
// initialize convert api | |
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret); | |
// define convert settings | |
var settings = new groupdocs_conversion_cloud.ConvertSettings(); | |
settings.storageName = myStorage; | |
settings.filePath = "sample.msg"; // input file | |
settings.format = "pdf"; // output format | |
settings.outputPath = "output.pdf"; | |
// define eml load options | |
var loadOptions = new groupdocs_conversion_cloud.MsgLoadOptions(); | |
loadOptions.convertAttachments = true; | |
settings.loadOptions = loadOptions; | |
// create convert document request | |
var request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings); | |
// convert document | |
convertApi.convertDocument(request); | |
console.log("Document converted successfully: " + response[0].url); |

Convert Email Attachments to PDF using REST API in Node.js
Try Online
Please try the following free online EML to PDF and MSG to PDF conversion tools, which are developed using the above API.
- https://products.groupdocs.app/conversion/eml-to-pdf
- https://products.groupdocs.app/conversion/msg-to-pdf
Conclusion
In this article, you have learned how to convert emails and Outlook messages to PDF documents using Node.js on the cloud. You have also learned how to convert Outlook MSG files to PDF documents using Node.js. Moreover, you have learned how to convert email attachments to PDF documents programmatically. This article also explained how to programmatically upload the EML file on the cloud and then download the converted PDF file from the cloud. 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. In case of any ambiguity, please feel free to contact us on the forum.