Last post Aug 10, 2018 04:10 PM by simflex
Aug 09, 2018 08:55 PM|simflex|LINK
I am using itextsharp to convert html to PDF.
In one instance, I have an image on the body of the html text:
body = body + " <td rowspan='6' style='white-space: nowrap;' width='10%'>";
body = body + " <div><img src='http://localhost:55319/images/price.png' width='56' height='209'/></div>";
body = body + " </td>";
When this renders, it creates a nice PDF
file with the image displaying.
However, a copy of the same data that is displayed in PDF is also displayed in the body of the outlook mail for the user.
The problem is that the image that displays on the PDF file is not rendering on the body of outlook mail.
It displays x on that section of the page.
Any ideas why?
Aug 09, 2018 09:09 PM|PatriceSc|LINK
It is expected. localhost is the local machine and at best each user would need to have a site on its own machine and even if using a public web site most mail clients are blocking external images by default for privacy/safety reasons. U!sally images are
embedded inside the mail message. See http://www.systemnetmail.com/faq/4.4.aspx
Aug 09, 2018 09:18 PM|chaaraan|LINK
For the image to be displayed in the body of email, try giving relative path in the image source instead of the absolute path
Aug 09, 2018 10:59 PM|KathyW|LINK
"For the image to be displayed in the body of email, try giving relative path in the image source instead of the absolute path"
Email needs a full publicly reachable path to fetch images from a server, not a relative path. Your email client has no idea what the image path is relative to.
Aug 10, 2018 03:23 PM|simflex|LINK
Thank you all for your feedbacks.
Patrice, I like your solution very much, thank you.
My only question is that given that I want this image to appear on that particular part of the page where I have currently have it, how do I link the code your provided, the code below?
//<img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:companylogo>", null, "text/html");
//create the LinkedResource (embedded image)
LinkedResource logo = new LinkedResource("c:\\inetpub\\wwwroot\\PDFCOnvert\\images\\price.png");
logo.ContentId = "companylogo";
//add the LinkedResource to the appropriate view
Aug 10, 2018 03:42 PM|PatriceSc|LINK
You'll have likely something such as :
body = body + " <div><img src='"+logoSrc+"' width='56' height='209'/></div>";
(logoSrc being just a parameter so that you can point to the source you need, possibly an embedded image) and then you'll have :
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
Aug 10, 2018 04:10 PM|simflex|LINK
Ok, I will figure out the rest.
Thanks for your help.