Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Write HTML in PDF with iTextSharp

Write HTML in PDF with iTextSharp

Scheduled Pinned Locked Moved ASP.NET
csharphtmlsysadminquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vnsraj
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups