// Create a Document object Document doc = new Document(PageSize.A4,20f,20f,0f,10f); // Create a new PdfWriter object, specifying the output stream StringWriter sw = new StringWriter(); HtmlTextWriter w = new HtmlTextWriter(sw); DivToPDF.RenderControl(w); //TbltoPDF.RenderControl(w); string s = sw.GetStringBuilder().ToString(); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, stream); // PdfWriter.GetInstance(doc, stream); StringReader sr = new StringReader(s); iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); //this creates a new destination to send the action to when the document is opened. The zoom in this instance is set to 0.75f (75%). Again I use doc.PageSize.Height to set the y coordinate to the top of the page. PdfDestination.XYZ is a specific PdfDestination Type that allows us to set the location and zoom. PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 0.75f); // Open the Document for writing doc.Open(); iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("App_Themes/BasicBlue/images/default_01.gif")); gif.Alignment = iTextSharp.text.Image.HEADER ; //gif.SetAbsolutePosition(30,760); gif.SetAbsolutePosition(320, 760); //gif.ScalePercent(75f, 75f); // change it's size // gif.ScaleToFit(300f, 100f); doc.Add(gif); iTextSharp.text.html.simpleparser.HTMLWorker parse = new iTextSharp.text.html.simpleparser.HTMLWorker(doc); parse.Style.LoadTagStyle("td", "size", "10px"); parse.Style.LoadTagStyle("body", "family", "Zurich BT"); //parse.Style.LoadTagStyle("td", "width", "20px"); parse.Parse(sr); //ArrayList parsed = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr, styles); //for (int k = 0; k < parsed.Count; k++) //{ // doc.Add((IElement)parsed[k]); //} doc.ClearTextWrap(); Byte[] buffer = stream.GetBuffer(); ////create a new action to send the document to our new destination. PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer); ////set the open action for our writer object writer.SetOpenAction(action); doc.Close(); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment;filename="+MemoNo); Response.AddHeader("content-length",buffer.Length.ToString().Trim()); Response.BinaryWrite(buffer); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.End(); writer.Close(); sr.Close();
<table> <tr> <td width="20%></td><br mode=" hold=" /><td width=80%></td><br mode="></td></tr></table>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)