Skip to main content

A professional Python package for converting EML email files to PDF format

Project description

EML to PDF Converter

A professional Python package for converting EML email files to PDF format with HTML rendering support for better email appearance.

Python Version License Code Style

Features

  • HTML Rendering: Preserves original email formatting and styling
  • Modern Appearance: Clean, professional PDF layout similar to modern email clients
  • Batch Processing: Convert multiple EML files at once
  • PDF Merging: Combine multiple PDFs into a single document
  • Error Handling: Robust error handling with detailed logging
  • Easy to Use: Simple command-line interface and Python API

Installation

Using pip

pip install eml-to-pdf

From source

git clone https://github.com/AlienZaki/eml-to-pdf.git
cd eml-to-pdf
pip install -e .

Quick Start

Command Line Usage

Convert all EML files in a directory to PDF:

eml-to-pdf convert /path/to/eml/files --output /path/to/output

Merge multiple PDFs into one file:

eml-to-pdf merge /path/to/pdf/files --output merged.pdf

Python API Usage

from eml_to_pdf import EMLToPDFConverter, PDFMerger

# Convert EML files to PDF
converter = EMLToPDFConverter(output_dir="pdf_output")
stats = converter.convert_directory("eml_files")
print(f"Converted {stats['successful']}/{stats['total']} files")

# Merge PDFs
merger = PDFMerger("merged_emails.pdf")
merger.merge_directory("pdf_output")

Requirements

  • Python 3.8+
  • WeasyPrint (for HTML to PDF conversion)
  • PyPDF2 (for PDF merging)

Dependencies

The package requires the following system dependencies:

Ubuntu/Debian

sudo apt-get install python3-dev python3-pip python3-cffi python3-brotli libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0

macOS

brew install pango

Windows

WeasyPrint should work out of the box on Windows.

Usage Examples

Basic Conversion

from eml_to_pdf import EMLToPDFConverter

# Initialize converter
converter = EMLToPDFConverter(output_dir="converted_pdfs")

# Convert single file
success = converter.convert_single_file("email.eml")

# Convert all files in directory
stats = converter.convert_directory("eml_files")
print(f"Successfully converted {stats['successful']} files")

Advanced Usage

from eml_to_pdf import EMLToPDFConverter, PDFMerger
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)

# Convert with custom settings
converter = EMLToPDFConverter(output_dir="custom_output")
stats = converter.convert_directory("eml_files")

# Merge with custom output name
merger = PDFMerger("my_emails.pdf")
success = merger.merge_directory("custom_output")

if success:
    size = merger.get_file_size()
    print(f"Created merged PDF: {size} bytes")

Command Line Examples

# Convert EML files
eml-to-pdf convert ./emails --output ./pdfs

# Merge PDFs
eml-to-pdf merge ./pdfs --output all_emails.pdf

# Convert and merge in one go
eml-to-pdf convert ./emails --output ./pdfs && eml-to-pdf merge ./pdfs --output all_emails.pdf

Project Structure

eml-to-pdf/
├── src/
│   └── eml_to_pdf/
│       ├── __init__.py
│       ├── converter.py      # EML to PDF conversion
│       └── merger.py         # PDF merging functionality
├── examples/
│   ├── basic_usage.py
│   └── advanced_usage.py
├── tests/
│   ├── test_converter.py
│   └── test_merger.py
├── docs/
│   └── api.md
├── README.md
├── setup.py
├── requirements.txt
└── LICENSE

API Reference

EMLToPDFConverter

__init__(output_dir: str = "pdf_output")

Initialize the converter with output directory.

convert_single_file(eml_file_path: str) -> bool

Convert a single EML file to PDF.

convert_directory(input_dir: str) -> Dict[str, int]

Convert all EML files in a directory.

PDFMerger

__init__(output_file: str = "merged.pdf")

Initialize the merger with output file path.

merge_files(pdf_files: List[str]) -> bool

Merge a list of PDF files.

merge_directory(input_dir: str, pattern: str = "*.pdf") -> bool

Merge all PDF files in a directory.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/AlienZaki/eml-to-pdf.git
cd eml-to-pdf

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -e .
pip install -r requirements-dev.txt

# Run tests
pytest

# Run linting
black src/ tests/
flake8 src/ tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

v1.0.0

  • Initial release
  • EML to PDF conversion with HTML rendering
  • PDF merging functionality
  • Command-line interface
  • Python API

Support

If you encounter any issues or have questions, please:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. Contact the maintainers

Acknowledgments

  • WeasyPrint for HTML to PDF conversion
  • PyPDF2 for PDF manipulation
  • The Python community for excellent libraries and tools

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eml_to_pdf-1.0.0.tar.gz (162.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eml_to_pdf-1.0.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file eml_to_pdf-1.0.0.tar.gz.

File metadata

  • Download URL: eml_to_pdf-1.0.0.tar.gz
  • Upload date:
  • Size: 162.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eml_to_pdf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 41a168b8347b60fcdce33415f971d569fabf31419a5d6975565b64b2131c389d
MD5 4ce08d7ee0c4897a622981e4a69bf088
BLAKE2b-256 99cdabf7dc5c707c4dba6b6f52eacf527c5f6ad0c3f01a457dcc68fe3aab22c9

See more details on using hashes here.

File details

Details for the file eml_to_pdf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: eml_to_pdf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for eml_to_pdf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d724fb9f1b3b5692dc1e907e47046294b50884299c65c029c28c0c4c4dbbff78
MD5 219a9b6721378629807c49c61617b679
BLAKE2b-256 0a00c9cd0b8f5dafc35b09c22d928cb6bed35416e94f91af5e631362efbbf20e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page