Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. public ActionResult DownloadFile() //you can put string html as parameter
  2.         {
  3.             string html = System.IO.File.ReadAllText(@"C:\Users\User\Desktop\test.html");// or you can pass it as parameter
  4.             HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
  5.             doc.LoadHtml(html);
  6.             var htmlHead = doc.DocumentNode.SelectSingleNode("//head");
  7.             HtmlNode newPara = HtmlNode.CreateNode("<style>* { direction:rtl; }</style>");
  8.             htmlHead.ChildNodes.Add(newPara);
  9.             html = doc.DocumentNode.InnerHtml;
  10.             IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
  11.             byte[] fileBytes = Renderer.RenderHtmlAsPdf(html).BinaryData;
  12.             var fileName = string.Format(@"{0}.pdf", Guid.NewGuid());
  13.             return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
  14.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement