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.
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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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:
- Check the Issues page
- Create a new issue with detailed information
- Contact the maintainers
Acknowledgments
- WeasyPrint for HTML to PDF conversion
- PyPDF2 for PDF manipulation
- The Python community for excellent libraries and tools
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41a168b8347b60fcdce33415f971d569fabf31419a5d6975565b64b2131c389d
|
|
| MD5 |
4ce08d7ee0c4897a622981e4a69bf088
|
|
| BLAKE2b-256 |
99cdabf7dc5c707c4dba6b6f52eacf527c5f6ad0c3f01a457dcc68fe3aab22c9
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d724fb9f1b3b5692dc1e907e47046294b50884299c65c029c28c0c4c4dbbff78
|
|
| MD5 |
219a9b6721378629807c49c61617b679
|
|
| BLAKE2b-256 |
0a00c9cd0b8f5dafc35b09c22d928cb6bed35416e94f91af5e631362efbbf20e
|