protected void buttonClick(Object sender, EventArgs e)
{
Byte[] fileContent=PdfSharpConvert("<head></head><body style='color:red;'>My HTML Layout</body>");
string fileName = "New.pdf";
string[] stringParts = fileName.Split(new char[] { '.' });
string strType = stringParts[1];
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
//Set the content type as file extension
type
Response.ContentType = strType;
//Write the file content
this.Response.BinaryWrite(fileContent);
this.Response.End();
}
public static Byte[] PdfSharpConvert(String html)
{
Byte[] res = null;
using (MemoryStream ms = new MemoryStream())
{
var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);
pdf.Save(ms);
res = ms.ToArray();
}
return res;
}
HTML To PDF in asp.net C#, using iDiTect.Converter, easiler and 3 lines code to work
ReplyDeleteThank you so much.
ReplyDelete