How to convert eml to pdf java with timezone offset

In this tutorial you’ll discover how to convert eml to pdf java while correctly adjusting the timestamp for any timezone difference. Using GroupDocs.Conversion for Java, you’ll see a complete end‑to‑end workflow—from Maven setup, through loading an email with a custom offset, to streaming the resulting PDF files. The steps are written for Java 8+ developers who need reliable, archive‑ready PDFs that show the right local time.

Quick answers

  • What library handles the conversion? GroupDocs.Conversion for Java.
  • Which primary method sets the timezone? EmailLoadOptions.setTimeZoneOffset.
  • Do I need a license? A free trial works for testing; a full license is required for production.
  • Can I batch‑process many emails? Yes—wrap the conversion loop in a batch routine.
  • What Java version is required? JDK 8 or later.

What is convert eml to pdf java?

The phrase “convert eml to pdf java” describes the process of taking an email file (usually .eml or .msg) and generating a PDF document using Java code. This conversion is essential for archiving, legal compliance, and cross‑platform sharing because PDFs preserve layout and are universally viewable.

Why use GroupDocs.Conversion for Java?

GroupDocs.Conversion supports 70+ input and output formats, including .eml, .msg, .pdf, .docx, and image types. Its built‑in EmailLoadOptions lets you specify a timezone offset in milliseconds, guaranteeing that the PDF timestamps match the intended local time. The library processes files in a streaming fashion, which reduces memory usage by up to 80 % compared with loading the whole document into RAM.

Prerequisites

Before you start, make sure you have:

  1. Libraries & dependencies

    • GroupDocs.Conversion for Java version 25.2 or later.
  2. Environment

    • JDK 8+ installed and configured on your machine.
    • Maven as the build automation tool.
  3. Knowledge

    • Basic Java programming, especially file I/O.
    • Familiarity with Maven’s pom.xml structure.

Setting up GroupDocs.Conversion for Java

Installation information

Add the GroupDocs repository and the conversion dependency to your pom.xml:

<repositories>
   <repository>
      <id>repository.groupdocs.com</id>
      <name>GroupDocs Repository</name>
      <url>https://releases.groupdocs.com/conversion/java/</url>
   </repository>
</repositories>
<dependencies>
   <dependency>
      <groupId>com.groupdocs</groupId>
      <artifactId>groupdocs-conversion</artifactId>
      <version>25.2</version>
   </dependency>
</dependencies>

License acquisition

You can start with a free trial or request a temporary license for full functionality testing:

  • Free trial – Download the library and explore basic features.
  • Temporary license – Apply for a temporary license temporary license page.
  • Purchase – For long‑term use, consider buying a license from the official site.

Basic initialization

Below is the minimal code you need to create a Converter instance and load an email with a timezone offset:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.load.EmailLoadOptions;

// Initialize GroupDocs.Conversion with necessary load options for email files
EmailLoadOptions loadOptions = new EmailLoadOptions();
loadOptions.setTimeZoneOffset(7200000.0); // Set timezone offset in milliseconds (e.g., 2 hours)

How to set the timezone offset?

EmailLoadOptions is a configuration class that controls how email files are loaded for conversion. Load your email with a custom offset before conversion. The setTimeZoneOffset method accepts the offset in milliseconds, so a +2 hour shift equals 7200000. This adjustment rewrites the displayed timestamp in the generated PDF. By providing the offset, the library recalculates the displayed send and receive times, ensuring that the generated PDF reflects the recipient’s local time zone. This is especially useful for multinational teams reviewing archived communications.

EmailLoadOptions loadOptions = new EmailLoadOptions();
loadOptions.setTimeZoneOffset(7200000.0); // Set to 2 hours ahead (in milliseconds)

How to initialize the Converter object?

Converter is the main class that performs document conversion using the provided load options. Create a Converter by passing the source file path and a lambda that supplies the previously defined loadOptions. This ties the timezone setting to the conversion process. It reads the source email, applies the EmailLoadOptions settings—including the timezone offset—and prepares the output stream for PDF generation. Using a lambda ensures the options are evaluated at conversion time, which is helpful when processing multiple files with varying settings.

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;

String sourceFilePath = "YOUR_DOCUMENT_DIRECTORY/sample.eml"; // Path to the email document.
String outputPattern = "YOUR_OUTPUT_DIRECTORY/ConvertEmailWithTimezoneOffset-%d.pdf";

List<OutputStream> streamPool = new ArrayList<>();
Converter converter = new Converter(sourceFilePath, () -> loadOptions);
PdfConvertOptions options = new PdfConvertOptions();

How to execute the conversion and stream PDF pages?

PdfConvertOptions specifies settings for PDF output such as page size, compression, and image quality. Call the convert method, providing a PdfConvertOptions instance and an output stream for each page. The try‑finally block guarantees that all streams are closed, preventing resource leaks. After configuring the options, the convert method iterates over each page of the email, writing the PDF data to separate output streams. This approach allows you to handle large emails efficiently, as each page is processed and flushed individually, minimizing memory consumption.

try {
    converter.convert((SaveDocumentStreamForFileType) t -> {
        try {
            OutputStream outputStream = Files.newOutputStream(Paths.get(String.format(outputPattern, streamPool.size())));
            streamPool.add(outputStream);
            return outputStream;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }, options);
} finally {
    for (OutputStream outputStream : streamPool) {
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

Practical applications

  • Archiving emails – Store PDFs with accurate timestamps for legal or audit purposes.
  • Cross‑timezone collaboration – Teams across the globe see the same local time in converted documents.
  • Email reporting – Generate PDF reports that preserve original send/receive times for compliance.

You can embed this workflow into CRM systems, document management platforms, or automated batch jobs to streamline your document pipeline.

Performance considerations

  • Resource management – Close streams promptly (as shown) to free memory.
  • Batch processing – Loop over a collection of .eml files and reuse a single Converter instance when possible.
  • JVM tuning – Adjust heap size (-Xmx) for large batches to avoid OutOfMemoryError.

Common issues and solutions

SymptomLikely causeFix
NullPointerException at loadOptionsLoad options not passed correctlyEnsure the lambda () -> loadOptions is used when creating Converter.
PDF output is blankInput file path incorrect or file missingVerify sourceFilePath points to an existing .eml file.
Timezone not reflectedWrong offset value (e.g., seconds instead of milliseconds)Provide offset in milliseconds (e.g., 7200000 for +2 h).

Frequently asked questions

Q: What is GroupDocs.Conversion for Java?
A: It’s a powerful library that enables document conversion across dozens of formats, including email to PDF, with built‑in timezone handling.

Q: How do I set the timezone offset for emails?
A: Use EmailLoadOptions.setTimeZoneOffset(milliseconds) before initializing the Converter.

Q: Can I convert multiple email formats with this setup?
A: Yes, the library supports .eml, .msg, and other common email file types.

Q: What are common pitfalls during conversion?
A: Missing dependencies, incorrect file paths, and providing the offset in the wrong unit (seconds vs. milliseconds).

Q: Where can I find more resources on GroupDocs.Conversion?
A: Visit the official documentation for detailed guides and API references.

Additional resources

Embrace the power of GroupDocs.Conversion for your Java applications and enjoy accurate, timezone‑aware PDF conversions today!


Last Updated: 2026-09-25
Tested With: GroupDocs.Conversion 25.2
Author: GroupDocs