Create PDF from HTML in asp.net
This is a simple article to generate pdf from html string. Just call the below code snippet .Here i am using NReco.PdfGenerator.dll to generate pdf.
NmaeSpace
using System.Text;
using System.IO;
using NReco;
protected void
Button4_Click(object sender, EventArgs e)
{
string PdfPath= "Pdf"+new Random().Next().ToString();
var htmlContent = String.Format("Hello Test <b>PDF</b>" ); // html string come here
var htmlToPdf = new
NReco.PdfGenerator.HtmlToPdfConverter();
var pdfBytes = htmlToPdf.GeneratePdf(htmlContent);
FileStream file = File.Create(Server.MapPath("~/PDF/"+PdfPath+".pdf"));
file.Write(pdfBytes, 0, pdfBytes.Length);
file.Close();
}
Add reference of NReco.PdfGenerator.dll
download the above dll from below link
http://www.nrecosite.com/pdf_generator_net.aspx
Comments
Post a Comment