iTextSharp html image parsing issue
-
The problem Using itextSharp to convert an html file to pdf and emailing it, I am unable to successfully parse an html file on the web server backend even when doing "absolute" or "relative" image referencing itextSharp fails and says "unable to find file c:\my_image.jpg" this is crazy didn’t specify c:\my_image.jpg as a path !!! The madness of all this is it works well on my local file system, when the html file is located on asp.net using an IIS webserver i get the above described error. Here is my code.
// Simple copy of the html  asp.net code behind private void SendEmail(string attachmentName, string pdfDocumentHtml, string mailSubject, string mailBody, MailAddress fromEmailAddress, List toMailAddressCollection) { Document doc = null; XmlTextReader reader = null; MemoryStream ms = null; MemoryStream msPdf = null; MemoryStream msHtml = null; try { /* Convert to PDF */ doc = new Document(PageSize.A4, 10, 10, 10, 10); msPdf = new MemoryStream(); PdfWriter.GetInstance(doc, msPdf); /* Create a pdf document listner to the memory data strean */ msHtml = new MemoryStream(new ASCIIEncoding().GetBytes(pdfDocumentHtml)); reader = new XmlTextReader(msHtml); reader.WhitespaceHandling = WhitespaceHandling.None; HtmlParser.Parse(doc, reader); ms = new MemoryStream(msPdf.ToArray()); /* Mail and add PDF as Attachment*/ var attachment = new Attachment(ms, new ContentType("application/pdf")); attachment.Name = attachmentName; attachment.NameEncoding = Encoding.UTF8; MailMessage email = new MailMessage(); email.From = fromEmailAddress; foreach (MailAddress address in toMailAddressCollection) { email.To.Add(address); } email.Attachmen
-
The problem Using itextSharp to convert an html file to pdf and emailing it, I am unable to successfully parse an html file on the web server backend even when doing "absolute" or "relative" image referencing itextSharp fails and says "unable to find file c:\my_image.jpg" this is crazy didn’t specify c:\my_image.jpg as a path !!! The madness of all this is it works well on my local file system, when the html file is located on asp.net using an IIS webserver i get the above described error. Here is my code.
// Simple copy of the html  asp.net code behind private void SendEmail(string attachmentName, string pdfDocumentHtml, string mailSubject, string mailBody, MailAddress fromEmailAddress, List toMailAddressCollection) { Document doc = null; XmlTextReader reader = null; MemoryStream ms = null; MemoryStream msPdf = null; MemoryStream msHtml = null; try { /* Convert to PDF */ doc = new Document(PageSize.A4, 10, 10, 10, 10); msPdf = new MemoryStream(); PdfWriter.GetInstance(doc, msPdf); /* Create a pdf document listner to the memory data strean */ msHtml = new MemoryStream(new ASCIIEncoding().GetBytes(pdfDocumentHtml)); reader = new XmlTextReader(msHtml); reader.WhitespaceHandling = WhitespaceHandling.None; HtmlParser.Parse(doc, reader); ms = new MemoryStream(msPdf.ToArray()); /* Mail and add PDF as Attachment*/ var attachment = new Attachment(ms, new ContentType("application/pdf")); attachment.Name = attachmentName; attachment.NameEncoding = Encoding.UTF8; MailMessage email = new MailMessage(); email.From = fromEmailAddress; foreach (MailAddress address in toMailAddressCollection) { email.To.Add(address); } email.Attachmen
Anyone??
Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.