22-08-23 07:21 AM
Hello BP Community,
is there any custom code available to save outlook email as a PDF file ?
I did create a custom code but it did not look like when we do print and save as a PDF manually.
Looking forward the solutions.
#EmailasPDF#Outlook#msgtopdf #emailconvertToPdf
Thanks,
Vidhya.
22-08-23 01:23 PM
Hi Vidhya,
I have previously used the MS Interoperability objects to create a Word doc from the HTML code in the email and then convert to PDF from there. In C#
In my global code I have the following methods:
private static string TrimHtmlString(string htmlString)
{
string xml = "<?xml";
string html = "<html";
string head = "<head";
string title = "<title";
string style = "<style";
string body = "<body";
bool hasXml = htmlString.Contains(xml);
bool hasHtml = htmlString.Contains(html);
bool hasHead = htmlString.Contains(head);
bool hasTitle = htmlString.Contains(title);
bool hasStyle = htmlString.Contains(style);
bool hasBody = htmlString.Contains(body);
int indexXml = htmlString.IndexOf(xml);
int indexHtml = htmlString.IndexOf(html);
int indexHead = htmlString.IndexOf(head);
int indexTitle = htmlString.IndexOf(title);
int indexStyle = htmlString.IndexOf(style);
int indexBody = htmlString.IndexOf(body);
string htmlSubString = string.Empty;
if (hasXml)
{
if (indexHtml == -1) { indexHtml = 999999999; }
if (indexHead == -1) { indexHead = 999999999; }
if (indexTitle == -1) { indexTitle = 999999999; }
if (indexStyle == -1) { indexStyle = 999999999; }
if (indexBody == -1) { indexBody = 999999999; }
int firstIndex = indexHtml;
if (indexHead < firstIndex) { firstIndex = indexHead; }
if (indexTitle < firstIndex) { firstIndex = indexTitle; }
if (indexStyle < firstIndex) { firstIndex = indexStyle; }
if (indexBody < firstIndex) { firstIndex = indexBody; }
htmlSubString = htmlString.Substring(firstIndex, htmlString.Length - firstIndex);
}
else
{
htmlSubString = htmlString;
}
return htmlSubString;
}
I call this from the page code stage like this:
The following code options need to be added:
23-08-23 08:48 AM
Thanks @SimonCooke1! I will try this. Really Appreciate your help!
06-09-23 01:03 PM
Hi Vidhya
I also have the same need (save email as PDF file).
Do the solution proposed by Simon worked for you ?
What is the difference between Simon implementation and just
I know images will be lost but besides that ? Does Simon solution preserves images ?
20-09-23 04:47 AM
I didn't get a chance to try Simon Cooke code.
But I've developed a code to convert as pdf but the look & feel is not match when do print on email.
My version of code will convert the .msg to .pdf like below,
11-12-23 08:15 AM
Hello Vidhya,
Could you please provide your code snippet? or any other better solutions you founded for email to PDF conversion.
Thanks,
Sajid
05-02-24 04:14 PM
Hi Team,
I have the same question too. I tried to incorporate the code as it was given by Simon Cooke. However, I am not able to arrange the office Microsoft.Office.Interop.Word.dll file. Could you please help me with this ?
a week ago
Hi Vidhya,
could you please provide the code snippet. I also have a need to convert msg to PDF
Thanks
Henry