1. Produk
  2.   Surel
  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.

Apa itu Email-to-PDF Converter?

Di ruang kerja digital saat ini, kemampuan untuk mengonversi komunikasi email menjadi dokumen PDF yang permanen dan dapat dibawa ke mana saja menjadi semakin berharga. Email-to-PDF Converter (sebelumnya EML to PDF Converter) adalah perpustakaan Java yang serbaguna yang menyelesaikan masalah ini secara tepat. Tersedia di GitHub, alat sumber terbuka ini memberikan pengembang dan organisasi cara yang dapat diandalkan untuk mengubah file email (.eml dan .msg) menjadi dokumen PDF profesional yang mempertahankan format, lampiran, dan metadata.

Email to PDF Converter adalah alat berbasis Java yang serbaguna yang mengonversi file email menjadi format PDF sambil mempertahankan format, gambar inline, dan lampiran. Awalnya dikembangkan oleh Nick Russler, proyek berlisensi Apache ini menawarkan tiga mode penggunaan yang berbeda: sebagai perpustakaan Java untuk integrasi ke dalam aplikasi, sebagai utilitas baris perintah untuk pemrosesan batch, dan sebagai aplikasi desktop dengan antarmuka grafis. Perpustakaan ini menangani proses kompleks parsing struktur email, membersihkan header MIME yang rusak, mengonversi konten ke HTML, dan akhirnya merendernya sebagai PDF menggunakan mesin render wkhtmltopdf yang kuat.

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.

 Indonesia