Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult DownloadFile() //you can put string html as parameter
- {
- string html = System.IO.File.ReadAllText(@"C:\Users\User\Desktop\test.html");// or you can pass it as parameter
- HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
- doc.LoadHtml(html);
- var htmlHead = doc.DocumentNode.SelectSingleNode("//head");
- HtmlNode newPara = HtmlNode.CreateNode("<style>* { direction:rtl; }</style>");
- htmlHead.ChildNodes.Add(newPara);
- html = doc.DocumentNode.InnerHtml;
- IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
- byte[] fileBytes = Renderer.RenderHtmlAsPdf(html).BinaryData;
- var fileName = string.Format(@"{0}.pdf", Guid.NewGuid());
- return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement