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 just mail me at hasannaqi9@gmail.com and i will be ready to give code of any problem.How you like my blog, just comment below.
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 just mail me at hasannaqi9@gmail.com and i will be ready to give code of any problem.How you like my blog, just comment below.
Comments
Post a Comment