anthny wrote:It looks like many one interested in this topic. Hope you have a little bit of your time to help with this.
Hi,
First point regarding images. You don't need to use the absolute image url to add an image you can use:
doc.Add(Image.GetInstance(Server.MapPath("~/content/images/logo.jpg")));
Secondly, I have an improved templating solution that I hope to add to nopCommerce in the next month or so. This will give you much more control over both email message templates and PDFs.
But to help you out in the meantime, iTextSharp has a HTMLWorker object that does an okay job of converting a html document into a PDF so things like tables are quite easy to do.
The code below (written for another application) passes a string result (contains the html to convert) to the HTMLWorker.Parse method. This creates a number of elements to be added to the PDF document.
string result = _templateService.RenderTemplate("TestEmail.htm", objs);
StyleSheet stylesheet = new StyleSheet();
stylesheet.LoadTagStyle("body", "color", "darkblue");
stylesheet.LoadTagStyle("body", "size", "10px");
var html = HTMLWorker.ParseToList(new StringReader(result), stylesheet);
using (MemoryStream ms = new MemoryStream())
{
var writer = PdfWriter.GetInstance(doc, ms);
doc.Open();
doc.Add(Image.GetInstance(Server.MapPath("~/content/images/logo.jpg")));
doc.Add(new Paragraph());
foreach (var e in html) {
doc.Add((IElement)e);
}
doc.Close();
Hope this helps some people in the meantime.
Ben