Conversion from .eml to pdf

hi team,
i have a scenario like to save .eml to pdf
can u suggest some activities or vb script on this
please suggest something

1 Like

@Nikhil_Katta

A little help from chatgpt will give you something like this…try to modify or ask it to correct if needed

using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

class Program
{
    static void Main(string[] args)
    {
        // Load EML file content
        string emlContent = File.ReadAllText("example.eml");

        // Create PDF file
        using (FileStream fs = new FileStream("example.pdf", FileMode.Create))
        {
            PdfWriter writer = new PdfWriter(fs);
            PdfDocument pdf = new PdfDocument(writer);
            Document document = new Document(pdf);

            // Write EML content to PDF
            Paragraph paragraph = new Paragraph(emlContent);
            document.Add(paragraph);

            document.Close();
        }
    }
}

Note: this is a direct chatgpt dump…dont use directly as using ,class etc are not supportes in invoke code…rather import what you need and use the code accordingly

Cheers

1 Like

Hi @Nikhil_Katta,
This this custom activity used to save emails as a pdf.
Link: Save Email as PDF File - RPA Component | UiPath Marketplace | Overview

Hope it helps you!


### Approach 1: Use Microsoft Outlook

If you have Microsoft Outlook installed, you can automate the process of opening the `.eml` file in Outlook and then using the "Save As" feature to save it as a `.pdf`.

1. **Start Process**: Use "Start Process" activity to open the `.eml` file in Outlook.
2. **Click Activity**: Automate the "File" > "Save As" > "PDF" sequence in Outlook's UI.
3. **Type Into / Set Text**: Automate the file naming and saving process.

### Approach 2: Use a VB Script with a Compatible Email Client

If you want to use a VB Script, you would typically automate an email client that supports scripting, such as Outlook, to save the email as a PDF.

Here's a simplified example of what the VBScript might look like:

vbscript

Set outlookApp = CreateObject("Outlook.Application")
Set mail = outlookApp.CreateItemFromTemplate("C:\path\to\your\email.eml")
' Assuming Outlook 2013 or later, which supports saving as PDF
mail.SaveAs "C:\path\to\your\output.pdf", 17


You would run this script using the "Invoke VBA" activity within an "Excel Application Scope" or execute it as a standalone script using the "Invoke Method" activity or a batch script.

Please note that automating email clients or using scripts to convert `.eml` to `.pdf` could be complex and might require setting up proper security permissions. Always test your solution thoroughly.
1 Like

Hi @Nikhil_Katta

You already have 2 ways to convert .eml to pdf. In the avove answers.

Below is 3rd way.

You can use the Save Mail Message activity to save the email as a *.eml file and then open it in Outlook. Then, you can use the Send Hotkey activity to print the email to PDF by sending Ctrl+P and selecting Microsoft Print to PDF as the printer. You can also use the Type Into activity to enter the file name and location for the PDF file.

1 Like