1. Товары
  2.   Эл. адрес
  3.   Java
  4.   Email-to-PDF Converter
 
  

Free Java Email Library to Convert EML & MSG to PDF

Open Source Java Email Processing Library for Converting Email Files (EML, MSG) to PDF. It Supports Handling Attachments and Inline Images and Multiple Email Formats inside Java apps.

What is Email-to-PDF Converter?

В современном цифровом рабочем пространстве возможность преобразовывать электронные сообщения в постоянные, переносимые PDF‑документы становится всё более ценной. Email-to-PDF Converter (ранее EML to PDF Converter) — это универсальная Java‑библиотека, решающая именно эту задачу. Доступный на GitHub, этот open‑source инструмент предоставляет разработчикам и организациям надёжный способ преобразовать файлы электронной почты (.eml и .msg) в профессиональные PDF‑документы, сохраняющие форматирование, вложения и метаданные.

Email to PDF Converter — это универсальный инструмент на Java, который конвертирует файлы электронной почты в формат PDF, сохраняя при этом форматирование, встроенные изображения и вложения. Изначально разработанный Ником Расслером, проект под лицензией Apache предлагает три различных режима использования: как Java‑библиотека для интеграции в приложения, как утилита командной строки для пакетной обработки и как настольное приложение с графическим интерфейсом. Библиотека решает сложный процесс разбора структуры писем, очистки некорректных MIME‑заголовков, преобразования содержимого в HTML и, в конечном итоге, рендеринга в PDF с помощью мощного движка wkhtmltopdf.

Previous Next

Getting Started with Email-to-PDF Converter

Before using the Email-to-PDF Converter, ensure you have Java runtime environment and wkhtmltopdf. Latest releases are available on the GitHub repository, including windows setup.exe installer and platform-independent JAR file.

Install Email-to-PDF Converter Library via GitHub

git clone https://github.com/nickrussler/email-to-pdf-converter.git 

You can download the library directly from GitHub page.

Intelligent Email File Conversion to PDF via Java

TThe Email to PDF Converter library provides a comprehensive solution for transforming email files into universally accessible PDF documents inside Java apps. At its core, the library parses email MIME structures and converts them into clean, well-formatted HTML before PDF generation. This approach ensures that complex email layouts, styled text, and embedded elements render correctly in the final document. This basic example takes an EML file and converts it to PDF using default settings. The library handles all the complexity of parsing the email structure, extracting inline content, and generating the final PDF.

How to Convert EML Email File to PDF Documents via Java Library?

 
import mimeparser.MimeMessageConverter;
import java.io.File;

public class EmailConverterExample {
    public static void main(String[] args) {
        try {
            File emailFile = new File("example.eml");
            File outputPdf = new File("output.pdf");
            
            // Perform the conversion
            MimeMessageConverter.convertToPdf(emailFile, outputPdf);
            
            System.out.println("Conversion completed successfully!");
        } catch (Exception e) {
            System.err.println("Error during conversion: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
 

Handle Attachment during Email to PDF Conversion via Java

The Email-to-PDF Converter library has provided options for extracting email attachments separately. Users can configure whether to extract attachments to a dedicated directory and optionally include a list of attachment names within the PDF document itself. The following code example demonstrates how to parse an email message separately from the conversion process, allowing for inspection or modification of email content before PDF generation. The ConversionOptions object provides programmatic access to all configuration parameters available in the command-line interface.

How Manage Attachments during Email to PDF Conversion via Java?

 
import mimeparser.MimeMessageConverter;
import mimeparser.MimeMessageParser;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;

public class AttachmentHandler {
    public static void main(String[] args) {
        try {
            File emailFile = new File("email-with-attachments.eml");
            
            // Parse the email
            MimeMessageParser parser = new MimeMessageParser();
            parser.parse(new FileInputStream(emailFile));
            
            // Access attachment information
            List attachments = parser.getAttachmentList();
            
            System.out.println("Found " + attachments.size() + " attachments:");
            for (File attachment : attachments) {
                System.out.println("- " + attachment.getName());
            }
            
            // Convert with attachment extraction
            ConversionOptions options = new ConversionOptions();
            options.setExtractAttachments(true);
            options.setAddAttachmentNames(true);
            
            MimeMessageConverter.convertToPdf(
                parser, 
                new File("output-with-attachments.pdf"), 
                options
            );
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Multiple Email Format Support

The Email-to-PDF Converter supports both EML and MSG file formats, making it compatible with various email clients. EML files are standard text-based email formats used by many email applications, while MSG files are Microsoft Outlook's proprietary email format. This dual-format support ensures flexibility across different email ecosystems.

Inline Image Handling While Email to PDF Export

One of the standout features is proper handling of inline images embedded within email bodies. The open source Email-to-PDF Converter library correctly identifies and processes these images, ensuring they appear in the appropriate locations within the PDF output rather than as separate attachments.

 Русский