<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Master Unlock Code</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <div style="text-align:center"> <img src="images/logo.png" style="width: 185px; height: 200px" /></div> <div> <span style="font-size: 14pt; color: red"><em>Customer Name: Pham Duy Hoa</em></span><br /> <span><em>Customer Phone</em>: <strong>0937927904</strong></span><br /> <span><em>Customer Address</em>: <strong>TCH05</strong></span><br /> <span><em>Date Invoice</em>:<strong> 02/06/2011</strong></span><br /> </div>
private string ReadHTMLCode(string URL) { try { WebClient webClient = new WebClient(); byte[] reqHTML = webClient.DownloadData(URL); UTF8Encoding objUTF8 = new UTF8Encoding(); return objUTF8.GetString(reqHTML); } catch (Exception Ex) { } return "error"; } protected void Button1_Click(object sender, System.EventArgs e) { String htmlText = ReadHTMLCode(("http://localhost:52978/WebSite22/Default.aspx")).Replace("\"", "'").Replace("px", "").Replace("images", "http://localhost:52978/WebSite22/images").Replace("color", "").Replace("function", ""); HTMLToPdf(htmlText, "PDFfile.pdf"); } public void HTMLToPdf(string HTML, string FilePath) { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\PDFfile.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.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Parse(new StringReader(HTML)); document.Close(); ShowPdf("PDFfile.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(); }
{ color:Red; font-family:Times New Roman; font-size:13px ; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)