eml2pdf is a command-line utility that converts .eml
email files to PDF format. It processes either a single .eml
file or all .eml
files in a specified input directory, converts each email to an individual PDF file (prefixed with the email's date and subject), and optionally merges them into a single PDF sorted by date (oldest to newest).
-
Convert Emails to PDF:
Converts each.eml
file into a PDF using mailparser and puppeteer. -
Custom File Naming:
Each PDF is named in the format:YYYY-MM-DD Subject.pdf
where the date is derived from the email and the subject is sanitized for safe filenames. -
Optional PDF Merging:
Merge all individual PDFs into one combined PDF (sorted by date) using pdf-lib. -
Simple CLI Interface:
Easily install and run the utility from the command line.
To install eml2pdf globally via npm, run:
npm install -g eml2pdf
This installs the command-line tool so you can run eml2pdf from anywhere.
The basic command-line usage is:
eml2pdf <input_directory|input_file> <output_directory> [combined_pdf_filename]
-
<input_directory|input file>
: Path to single.eml
file a directory containing multiple.eml
files. -
<output_directory>
: Directory where the generated PDF files will be saved. -
[combined_pdf_filename]
(optional): If provided, after converting individual emails, the tool will merge them into a single PDF with this name. If the filename does not end with .pdf, the extension will be appended automatically.
Convert single .eml file to a PDF
eml2pdf /path/to/eml/file.eml /path/to/output
Convert .eml files to individual PDFs
eml2pdf /path/to/eml/files /path/to/output
Convert and Merge into a Single PDF
eml2pdf /path/to/eml/files /path/to/output all_emails.pdf
In the above example, the tool converts each .eml
file into a PDF named with its date and subject, and then merges them into a file named all_emails.pdf sorted from oldest to newest.
- Email Parsing: The utility reads each .eml file and uses mailparser to extract email content, including the date and subject.
- PDF Generation: The email content is rendered as HTML and converted into a PDF (A4 format) using puppeteer.
- File Naming: Each PDF file is named in the format YYYY-MM-DD Subject.pdf, where the date is in the YYYY-MM-DD format and the subject is sanitized for use in file names.
- PDF Merging: If a combined PDF filename is provided, the tool sorts the individual PDFs by the date (oldest to newest) and merges them into a single document using pdf-lib.
- Node.js: Version 14 or later is recommended.
- npm: Comes with Node.js.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please fork the repository and submit pull requests with your improvements or bug fixes. If you encounter any issues, feel free to open an issue on GitHub.