Hello Everyone,
Hope everyone is fine.
I have HTML content and want to convert that to pdf format and save it to a local project folder.
I have installed HtmlRender.PdfSharp NuGet library in my project.
I have also tried a few examples but did not work out. Even I did not find any error in that code.
So I am not getting, what I am doing wrong.
I have tried the following code :
- 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);
-
- Response.ContentType = strType;
-
- 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;
- }
Please let me know anything can be done to fix these.
Thank you in advance.