
Save Every Outlook Email as PDF in Google Drive using PDF.co and n8n
3 MIN READ
5 MIN READ
In this detailed tutorial, we will guide you through the process of converting an email file (either .eml or .msg) to a PDF document using the PDF.co Web API in Python. We will use a sample .eml file for this demonstration, but you can apply the same steps to .msg files as well.
Before starting, you need to install the requests library. This Python library is essential for making HTTP requests to the PDF.co Web API, which will allow you to interact with PDF.co’s services.
requests module: python -m pip install requestsThis will install the requests library in your Python environment, enabling you to communicate with the PDF.co Web API.
Next, you need to prepare the Python script that will handle the conversion of the email file into a PDF.
Now that you have the sample code, let’s configure it with your specific settings.
paperSize parameter in the code to match your requirements.embedAttachments to True in Python if the output should include the email’s attachments. Set it to False to convert only the email body.convertAttachments to True to convert supported attachment types into PDF pages and merge them into the output. Unsupported formats remain embedded files.convertAttachments to False to retain the original files as embedded attachments instead. See the current supported-format list.Once you have updated the code with your API Key, email file URL, and parameter settings, save the Python program in your preferred directory.
Now, execute the program. If everything is configured correctly, the program will start the email-to-PDF conversion. Once the conversion is complete, you will receive a generated PDF URL.
After the script finishes running and the PDF file has been generated, open the output PDF using your preferred PDF viewer. You should now see the content of your email file converted into a neatly formatted PDF document.
You’ve learned how to convert email to PDF in Python using PDF Extractor API with this tutorial. This is just one of the examples of how PDF.co Web API can make things easier for Python developers.
Create an account, get an API key and test a request.