foreach (DataRow dr in dt.Rows) { //htmlTable.Append("<div //style='page-break-before: always'>"); htmlTable.Append("<div style='font-weight:bold; text-align: center;'></div>"); htmlTable.Append("<table border='1' width='80%'>"); htmlTable.Append("<tr>"); htmlTable.Append("</tr>"); int k = 1; string qry1 = "select * from tb where No='" + NO + "' and Name='" + SelectedValue.ToString() + "'"; htmlTable.Append("</table>"); htmlTable.Append("<br/>"); // //htmlTable.Append("<div style='text-align: right; //'>(" + name + ")</div>"); htmlTable.Append("<table border='0' float='right'>"); htmlTable.Append("<tr>"); htmlTable.Append("<td> </td>"); htmlTable.Append("<td> </td>"); htmlTable.Append("<td> </td>"); htmlTable.Append("<td>(" + name + ")</td>"); htmlTable.Append("</tr>"); htmlTable.Append("</table>"); // htmlTable.Append("<br/>"); //htmlTable.Append("<div style='width:20%; //text-align: right;'>(" + address + ")</div>"); htmlTable.Append("<table border='0' float='right'>"); htmlTable.Append("<tr>"); htmlTable.Append("<td> </td>"); htmlTable.Append("<td> </td>"); htmlTable.Append("<td> </td>"); htmlTable.Append("<td colspan='2'>R/o " + address + "</td>"); htmlTable.Append("</tr>"); htmlTable.Append("</table>"); //htmlTable.Append("<div style='position:absolute; //bottom:0; width:100%; height:60px;background:#6cf;' //>This is a footer. Page </div>"); //htmlTable.Append("<br/><br/>< // br/><br/>"); //htmlTable.Append("<div style=\"font-family: \'Arial\', sans-serif; color: #ccc; font-size: 10px; margin: 0 auto;text-align:center;bottom:0;position:fixed;\">Simple page footer aligned by center.</div>"); //htmlTable.Append("<div //style='page-break-after:always;'> </div>"); htmlTable.Append("<newpage />"); } lblResult.Text = htmlTable.ToString(); //Creating the object of the String Writer. StringWriter sw = new StringWriter(); // Creating the object of HTML Writer and passing the // object of String Writer to HTMl Text Writer HtmlTextWriter hw = new HtmlTextWriter(sw); //this.Page.RenderControl(hw); lblResult.RenderControl(hw); // Now whatever is rendered on the page, we will // give it to the object of the String reader so that we can StringReader srdr = new StringReader(sw.ToString()); // Creating the PDF DOCUMENT using the Document class // from Itextsharp.pdf namespace Document pdfDoc = new Document(PageSize.A4, 50F, 50F, 50F, 0.2F); // HTML Worker allows us to parse the HTML Content to the // PDF Document. To do this, we will pass the object // of Document class as a Parameter. // HTMLWorker hparse = new HTMLWorker(pdfDoc); HTMLWorkerExtended hparse = new HTMLWorkerExtended(pdfDoc); //using (var htmlWorker = new HTMLWorkerExtended() //{ // htmlWorker.Open(); // htmlWorker.Parse(htmlViewReader); //} // Finally we write data to PDF and open the Document PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); // Now we will pass the entire content that is stored // in String reader to HTML Worker object to achieve // the data from to String to HTML and then to PDF. hparse.Parse(srdr); pdfDoc.Close(); //Now finally we write to the PDF Document //using the Response.Write method. Response.ContentType = "application/pdf"; // Setting the // application // Assigning the // header Response.AddHeader("content-disposition", "attachment;filename=filename.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); } public class HTMLWorkerExtended : HTMLWorker { public HTMLWorkerExtended(Document document) : base(document) { } public override void StartElement(string tag, Hashtable h) { if (tag.Equals("newpage")) document.Add(Chunk.NEXTPAGE); else base.StartElement(tag, h); } }
htmlTable.Append("<div style='position:absolute; bottom:0; width:100%; height:60px;background:#6cf;'>This is a footer. Page </div>");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)