using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } protected void Button1_Click(object sender, System.EventArgs e) { String htmlText = "<font " + " color=\"#0000FF\"><b><i>Title One</i></b></font><font " + " color=\"black\"><br><br>Some text here<br><br><br><font " + " color=\"#0000FF\"><b><i>Another title here " + " </i></b></font><font " + " color=\"black\"><br><br>Text1<br>Text2<br><OL><LI><DIV Style='color:green'>Pham Duy Hoa</DIV></LI><LI>how are u</LI></OL><br/>"+ "<table border='1'><tr><td style='color:red;text-align:right;width:20%'>123456</td><td style='color:green;width:60%'>78910</td><td style='color:red;width:20%'>ASFAFA</td></tr><tr><td style='color:red;text-align:right'>123456</td><td style='color:green;width:60%'>78910</td><td style='color:red;width:20%'>DAFSDGAFW</td></tr></table><br/>"+ "<div><ol><li>123456</li><li>123456</li><li>123456</li><li>123456</li></ol></div>"; HTMLToPdf(htmlText, "PDFfile.pdf"); } public void HTMLToPdf(string HTML, string FilePath) { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\Chap0101.pdf", FileMode.Create)); document.Open(); Image pdfImage = Image.GetInstance(Server.MapPath("logo.png")); pdfImage.ScaleToFit(100, 50); pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760); document.Add(pdfImage); iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader(HTML)); document.Close(); ShowPdf("Chap0101.pdf"); } private void ShowPdf(string s) { Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "inline;filename=" + s); Response.ContentType = "application/pdf"; Response.WriteFile(s); Response.Flush(); Response.Clear(); } }
Dim jpeg As iTextSharp.text.Image Dim _Chunk As Chunk jpeg = iTextSharp.text.Image.GetInstance(imagepath) _Chunk = New Chunk(jpeg, 0, 0) document.Add(_Chunk);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)