Write HTML in PDF with iTextSharp
-
Hi All, I need to create pdf file using iTextSharp. I can write simple text in my pdf file. But How can I add html content in pdf file. I used string variable to hold html content. But when I use that variable my pdf file content not showing html format. my Code given below : private void createPDF() { //string newFile = @"N:\.NET\New Document.pdf"; string strContent = ""; StringWriter sw = new StringWriter(); string newFile = Server.MapPath("1.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(newFile, FileMode.Create)); // Metadata doc.AddCreator("PDF Printer by Joachim Tesznar"); doc.AddTitle("New PDF Document"); // Add content doc.Open(); sw.Write(GetMailBodyOrderDetails().ToString()); doc.Add(new Paragraph(sw.ToString())); doc.Close(); } #region string GetMailBodyOrderDetails() public string GetMailBodyOrderDetails() { StreamReader StmRdr1 = null; FileInfo fi1 = null; string strFileName1 = Request.PhysicalApplicationPath + "Registration.html"; fi1 = new FileInfo(strFileName1); if (fi1.Exists) { StmRdr1 = File.OpenText(strFileName1); StreamReaderStrLine1 = StmRdr1.ReadToEnd(); // StreamReaderStrLine1 = StreamReaderStrLine1.Replace("<TITLE>", ListingName).Replace("<PRICE>", Price.ToString()).Replace("<DESCRIPTION>", ListingDetail).Replace("<EMAIL>", Email).Replace("<COUNTRY>", Country).Replace("<STATE>", State).Replace("<SUBURB>", City).Replace("<TOPADS>", "No"); StreamReaderStrLine1 = StreamReaderStrLine1.Replace("\r\n", ""); StreamReaderStrLine1 = StreamReaderStrLine1.Replace("<!--body", ".body").Replace("}-->", "}").Replace("\t", ""); } return StreamReaderStrLine1; } #endregion please reply Thanks Raj