Posts

Showing posts from 2016
Generate PDF from HTML in c# You can use itextSharp and itextSharp.xmlWorker libraries to generate and download PDF from HTML, simply add reference of both the DLLs that are open source.The code is given below:             Byte[] bytes;             var ms = new MemoryStream();             var doc = new Document(PageSize.A4);             var writer = PdfWriter.GetInstance(doc, ms);             doc.Open();             var html = @"<strong>hi</strong>";             var sr = new StringReader(html);             var htmlWorker = new HTMLWorker(doc);             htmlWorker.Parse(sr);             doc.Close();             bytes = ms.ToArray();             HttpResponse response = HttpContext.Current.Response;             response.Clear();             response.AppendHeader("content-disposition",@"attachment;filename=""myfile.pdf""");             response.BinaryWrite(bytes);             response.End(); To know more