---
title: "Convert Email to PDF"
canonical_url: "https://www.compdf.com/guides/generation-sdk/dotnet-core/generation/email-to-pdf"
md_url: "https://www.compdf.com/guides/generation-sdk/dotnet-core/generation/email-to-pdf.md"
description: "ComPDF SDK Guides. In this developer's guide, all the details and how to use ComPDF for SDK Guides will be covered in depth."
---

# Convert Email to PDF

Convert an email file directly to a PDF file. Here is an example:

```csharp
string emailPath = "/mail.eml";
string pdfPath = "/mail.pdf";

// The result must be disposed, also when the conversion fails
using (CEmailResult result = CEmailConverter.ConvertToPdf(emailPath, pdfPath))
{
    if (result.IsSuccess())
    {
        Console.WriteLine("PDF conversion successful");
    }
    else
    {
        Console.WriteLine($"Conversion failed: {result.GetStatus()}, PDF error: {result.GetPdfError()}");
    }
}
```

Without page properties, the PDF uses A4 paper with 32 px top/bottom and 40 px left/right margins on every page.

## Convert an Email Stream to a PDF Stream

```csharp
using (FileStream emailStream = File.OpenRead("/mail.msg"))
using (FileStream pdfStream = File.Create("/mail.pdf"))
using (CEmailResult result = CEmailConverter.ConvertToPdf(emailStream, pdfStream))
{
    // If the conversion fails, pdfStream may contain partial data that must be discarded
}
```

The email stream is read from its current position to the end. Seekable streams are read in blocks by the SDK; other streams are read into memory first. You can also pass the email bytes directly: `CEmailConverter.ConvertToPdf(byte[] emailData, Stream pdfStream)`.
