---
title: "Converting email files to PDF | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/conversion/email-to-pdf/"
md_url: "https://www.nutrient.io/guides/java/conversion/email-to-pdf.md"
last_updated: "2026-06-09T21:11:56.021Z"
description: "Convert MSG and EML email files to PDF documents using Nutrient Java SDK."
---

# Converting email files to PDF

Convert email messages to PDF when you need standardized records for archiving, legal review, and compliance workflows. PDF output preserves message content in a format you can store, review, and share across teams.

Organizations often convert MSG and EML files to PDF for:

- Compliance archives

- Legal discovery

- Business record retention

## Implement email-to-PDF conversion with the Java SDK

Nutrient Java SDK provides email-to-PDF conversion through the `Document` API.

You don’t need to build:

- Custom email parsing logic

- External conversion pipelines

- Format-specific rendering code

## Prepare the project

Define a package and class:

```java

package io.nutrient.Sample;

```

Import required SDK classes:

```java

import io.nutrient.sdk.Document;
import io.nutrient.sdk.exceptions.NutrientException;

public class EmailToPDF {

```

Create a `main` method. This example declares `NutrientException` in the method signature:

```java

    public static void main(String[] args) throws NutrientException {

```

## Open the email file

Use `Document.open(...)` inside a [try-with-resources statement](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) so Java closes resources automatically:

```java

        try (Document document = Document.open("input.msg")) {

```

Use an absolute path or a path relative to the working directory. The SDK supports MSG and EML input.

## Export to PDF

Call `exportAsPdf(...)` to create the output file:

```java

            document.exportAsPdf("output.pdf");
        }
    }
}

```

## Handle errors

Nutrient Java SDK raises `NutrientException` when an operation fails. You can:

- Declare it in the method signature, as shown above

- Catch it with `try`/`catch` if you need custom error handling

## Summary

The conversion flow has two steps:

1. Open the email file.

2. Export it as PDF.

Download [this sample package](https://www.nutrient.io/downloads/samples/java/email-to-pdf.zip) to run the example locally.
---

## Related pages

- [Converting HTML to PDF](/guides/java/conversion/html-to-pdf.md)
- [Converting CAD files to PDF](/guides/java/conversion/cad-to-pdf.md)
- [Converting PDF documents to Excel format for data analysis](/guides/java/conversion/pdf-to-excel-document.md)
- [Nutrient Java SDK conversion guides](/guides/java/conversion.md)
- [Converting a document from XLSX to PDF format](/guides/java/conversion/excel-document-to-pdf.md)
- [Converting PDF documents to HTML format for web publishing](/guides/java/conversion/pdf-to-html.md)
- [Converting PDF documents to PDF/A format](/guides/java/conversion/pdf-to-pdf-a.md)
- [Converting a document from Markdown to PDF format](/guides/java/conversion/markdown-to-pdf.md)
- [Converting PDF documents to image format](/guides/java/conversion/pdf-to-image.md)
- [Converting PDF documents to PDF/UA format](/guides/java/conversion/pdf-to-pdf-ua.md)
- [Converting PDF documents to Markdown format](/guides/java/conversion/pdf-to-markdown.md)
- [Converting a document from PPTX to PDF format](/guides/java/conversion/powerpoint-document-to-pdf.md)
- [Converting a document from PDF to DOCX format](/guides/java/conversion/pdf-to-word-document.md)
- [Converting a document from DOCX to PDF format](/guides/java/conversion/word-document-to-pdf.md)
- [Converting a document from DOCX to PDF/UA format](/guides/java/conversion/word-document-to-pdf-ua.md)
- [Converting PDF documents to PowerPoint presentations](/guides/java/conversion/pdf-to-powerpoint-document.md)
- [Converting a Word document to PDF while preserving comments](/guides/java/conversion/word-document-to-pdf-including-comments.md)

