pdf. This is to do with the GridView.RenderControl method. An override method that is needed to export the GridViewīelow method need to keep on the page where you are writing the Export functionality in case you are trying to expor the GridView into. I will be using above function to generate the document for all 3 buttons shown in the 1st picture above. If anyone finds any better way parse the HTML in iTextSharp 5.0.2.0, kindly let me know by responding this article.Īt last if any error occurs write into the Label control else close the Document object in the finally block. NOTE: In the earlier version of iTextSharp HTMLParser.Parse method used to do the work that we are doing here using TextReader and looping through all the element but unfortunately in the iTextSharp 5.0.2.0 version I couldn't find this method, so I have written this work around. Next, it reads the string int the TextReader and then loop through each element find into the string using HTMLworker.ParseToList method and add them to the document. Later, if we do not pass any text into this method, then it bind the GridView and use GridView.RenderControl method to get the GridView html and append into the StringBuilder else append the text into the StringBuilder. pdf document to be downloable or not it fires PDFWriter.GetInstance method with Response.OutputStream or the name of the file with FileMode.Create. ParseToList(sReader, new StyleSheet ()) Ībove function, first creates a new instance of the Document object (found in the iTextSharp.dll) and based on whether we want the. Using ( TextReader sReader = new StringReader (strB.ToString())) now read the Grid html one by one and add into the document object Using ( HtmlTextWriter htWriter = new HtmlTextWriter (sWriter)) Using ( StringWriter sWriter = new StringWriter (strB)) StringBuilder strB = new StringBuilder () GetInstance(document, new FileStream (path + fileName, FileMode. GetInstance(document, Response.OutputStream) Private void GeneratePDF( string path, string fileName, bool download, string text) This method takes path, fileName, download and text parameters and act acordingly. Its code looks like below A common GeneratePDF method pdf generation, I have created a common function called GeneratePDF. You will have to use at least following namespaces to work for the sample provided with this article. aspx page looks like below.ĭo not worry about the hyperlink control have placed under GridView, here our moto is to explain the GridView data into. To show this example, I have taken 4 asp:Button controls and a asp:GridView control that will bind the data from the database. You can watch the video of this article at Lets start with designing the. To refer it in your project, right click it and select "Add Reference. pdf document using this article, you will need to download the Opern source.
0 Comments
Leave a Reply. |