This program converts .eml
files in a specified folder to .pdf
files and combines them into a single .pdf
file
after they have been sorted into chronological order.
- os
- re
- datetime
- html2pdf
- PyPDF2
- bs4
Note: Run pip install -r requirements.txt to install the required dependencies for the code to run.
This program consists of the following files:
eml2pdf_converter.py
: The main program.eml_processing.py
: The functions for processing the.eml
files.pdf_tools.py
: The functions for converting the html code into pdfs.requirements.txt
: The required libraries for the program.README.md
: This file.
This function extracts the text from an .eml
file. The text is returned as a string in html
format.
This function converts the html
string to a .pdf
file using the html2pdf
library.
This function combines a list of .pdf
files into a single .pdf
file using the PdfMerger
library.
This function extracts the date from an .eml
file. The date is returned as a string in the format YYYYMMDD
.
This function creates a folder for storing the converted .pdf
files if the folder does not already exist.
This function renames an .eml
file to include the date in the filename in the format YYYYMMDD_<filename>.eml
.
This function converts an .eml
file to a .pdf
file by calling the extract_text_from_eml
and text_to_pdf
functions.
This function combines .pdf
files into a single .pdf
file by calling the combine_pdfs
function.
This is the main function of the program which performs the following steps:
- Creates the
pdf_folder
for storing the converted.pdf
files. - Renames the
.eml
files in theeml_folder
to include the date in the filename. - Converts the
.eml
files in theeml_folder
to.pdf
files. - Combines the converted
.pdf
files into a single.pdf
file that is sorted chronologically.
- Ensure that the required libraries are installed.
- Place the
.eml
files in theeml_folder
(default is./emails
). - Run the program using
python eml2pdf_converter.py
. - The combined
.pdf
file will be stored in thepdf_folder
(default is./pdfs
).